Skip to content

Commit

Permalink
Fix a critical bug which made download not to work under Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Vihtakari committed Jul 5, 2023
1 parent bc12433 commit 6785791
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: ggOceanMaps
Type: Package
Title: Plot Data on Oceanographic Maps using 'ggplot2'
Version: 2.0.1
Date: 2023-07-04
Version: 2.0.2
Date: 2023-07-05
Authors@R: c(person("Mikko", "Vihtakari", email = "mikko.vihtakari@hi.no",
role = c("aut", "cre"),
comment = c(affiliation = "Institute of Marine Research",
Expand Down
2 changes: 1 addition & 1 deletion R/basemap.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
## Test parameters

# limits = c(160, -160, 60, 80); bathymetry = TRUE
# x = NULL; limits = NULL; data = NULL; shapefiles = NULL; crs = NULL; bathymetry = FALSE; glaciers = FALSE; rotate = FALSE; legends = TRUE; legend.position = "right"; lon.interval = NULL; lat.interval = NULL; bathy.style = NULL; bathy.border.col = NA; bathy.size = 0.1; bathy.alpha = 1; land.col = "grey60"; land.border.col = "black"; land.size = 0.1; gla.col = "grey95"; gla.border.col = "black"; gla.size = 0.1; grid.col = "grey70"; grid.size = 0.1; base_size = 11; projection.grid = FALSE; verbose = TRUE
# x = NULL; limits = NULL; data = NULL; shapefiles = NULL; crs = NULL; bathymetry = FALSE; glaciers = FALSE; rotate = FALSE; legends = TRUE; legend.position = "right"; lon.interval = NULL; lat.interval = NULL; bathy.style = NULL; downsample = 0; bathy.border.col = NA; bathy.size = 0.1; bathy.alpha = 1; land.col = "grey60"; land.border.col = "black"; land.size = 0.1; gla.col = "grey95"; gla.border.col = "black"; gla.size = 0.1; grid.col = "grey70"; grid.size = 0.1; base_size = 11; projection.grid = FALSE; verbose = TRUE

basemap <- function(x = NULL, limits = NULL, data = NULL, shapefiles = NULL, crs = NULL, bathymetry = FALSE, glaciers = FALSE, rotate = FALSE, legends = TRUE, legend.position = "right", lon.interval = NULL, lat.interval = NULL, bathy.style = NULL, downsample = 0, bathy.border.col = NA, bathy.size = 0.1, bathy.alpha = 1, land.col = "grey60", land.border.col = "black", land.size = 0.1, gla.col = "grey95", gla.border.col = "black", gla.size = 0.1, grid.col = "grey70", grid.size = 0.1, base_size = 11, projection.grid = FALSE, expand.factor = 1.1, verbose = FALSE) {

Expand Down
10 changes: 5 additions & 5 deletions R/load_map_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ load_map_data <- function(x, force = FALSE, downsample = 0) {
exist_list <- lapply(x[c("land", "glacier", "bathy")], function(k) {
if(is.null(k)) {
NULL
} else if(grepl("/", k)) {
} else if(grepl("/|\\\\", k)) {
if(file.exists(k) & !force) {
TRUE
} else {
Expand Down Expand Up @@ -97,11 +97,11 @@ load_map_data <- function(x, force = FALSE, downsample = 0) {
lapply(x[c("land", "glacier")], function(k) {
if(is.null(k)) {
NULL
} else if(grepl("/", k)) {
} else if(grepl("/|\\\\", k)) {
if(file.exists(k) & !force) {
mget(load(k))[[1]]
} else {
tmp <- unlist(strsplit(k, "/"))
tmp <- unlist(strsplit(k, "/|\\\\"))
dest_path <- file.path(normalizePath(getOption("ggOceanMaps.datapath")),tmp[length(tmp)])

download.file(paste0(x$path, tmp[length(tmp)]), dest_path)
Expand All @@ -118,11 +118,11 @@ load_map_data <- function(x, force = FALSE, downsample = 0) {
if(bathy_user_defined) {
x[["bathy"]] <- stars::read_stars(k, downsample = downsample)
} else {
if(grepl("/", k)) {
if(grepl("/|\\\\", k)) {
if(file.exists(k) & !force) {
x[["bathy"]] <- mget(load(k))[[1]]
} else {
tmp <- unlist(strsplit(k, "/"))
tmp <- unlist(strsplit(k, "/|\\\\"))
dest_path <- file.path(normalizePath(getOption("ggOceanMaps.datapath")),tmp[length(tmp)])

download.file(paste0(x$path, tmp[length(tmp)]), dest_path)
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
".ggOceanMapsenv <- new.env(); ",
".ggOceanMapsenv$datapath <- 'YourCustomPath'}",
". You can use usethis::edit_r_profile() to edit the file.",
" normalizePath('~/Documents/ggOceanMapsLargeData') ",
" '~/ggOceanMapsLargeData' ",
"would make it in a writable folder on most operating systems.")
} else {
msg <- paste0("ggOceanMaps: Using ", getOption("ggOceanMaps.datapath"),
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ While ggOceanMaps allows plotting any custom-made shapefiles, the package contai
.ggOceanMapsenv$datapath <- 'YourCustomPath'
```

It is smart to use a directory R has writing access to. For example `normalizePath("~/Documents/ggOceanMapsLargeData")` would work for most operating systems.
It is smart to use a directory R has writing access to. For example `"~/ggOceanMapsLargeData"` would work for most operating systems.

You will need to set up the data path to your .Rprofile file only once and ggOceanMaps will find the path even though you updated your R or packages. ggOceanMaps will inform you about your data path when you load the package.

Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# ggOceanMaps

**Plot data on oceanographic maps using ggplot2. R package version
2.0.0**
2.0.2**

<!-- badges: start -->

Expand Down Expand Up @@ -97,7 +97,7 @@ basemap(data = dt, bathymetry = TRUE) +
color = "red", fill = NA)
```

![](man/figures/README-unnamed-chunk-5-1.png)<!-- -->
![](man/figures/README-unnamed-chunk-4-1.png)<!-- -->

See the [ggOceanMaps
website](https://mikkovihtakari.github.io/ggOceanMaps/index.html),
Expand Down Expand Up @@ -133,8 +133,7 @@ computer by modifying your .Rprofile file
```

It is smart to use a directory R has writing access to. For example
`normalizePath("~/Documents/ggOceanMapsLargeData")` would work for most
operating systems.
`"~/ggOceanMapsLargeData"` would work for most operating systems.

You will need to set up the data path to your .Rprofile file only once
and ggOceanMaps will find the path even though you updated your R or
Expand Down Expand Up @@ -194,7 +193,7 @@ citation("ggOceanMaps")
#> To cite package 'ggOceanMaps' in publications use:
#>
#> Vihtakari M (2023). _ggOceanMaps: Plot Data on Oceanographic Maps
#> using 'ggplot2'_. R package version 2.0.0,
#> using 'ggplot2'_. R package version 2.0.2,
#> <https://mikkovihtakari.github.io/ggOceanMaps/>.
#>
#> A BibTeX entry for LaTeX users is
Expand All @@ -203,7 +202,7 @@ citation("ggOceanMaps")
#> title = {ggOceanMaps: Plot Data on Oceanographic Maps using 'ggplot2'},
#> author = {Mikko Vihtakari},
#> year = {2023},
#> note = {R package version 2.0.0},
#> note = {R package version 2.0.2},
#> url = {https://mikkovihtakari.github.io/ggOceanMaps/},
#> }
```
Expand Down
Binary file added man/figures/README-unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6785791

Please sign in to comment.