Skip to content

Commit

Permalink
order of arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
stineb committed Oct 25, 2023
1 parent 79a5bb3 commit 2c3222b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
22 changes: 11 additions & 11 deletions R/map2tidy.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
#'
#' @param nclist A vector of character strings specifying the complete paths to
#' files.
#' @param varnam The variable name(s) for which data is to be read from NetCDF
#' files.
#' @param lonnam The dimension name of longitude in the NetCDF files.
#' @param latnam The dimension name of latitude in the NetCDF files.
#' @param timenam The name of dimension variable used for timein the NetCDF
#' files. Defaults to \code{"time"}.
#' @param timedimnam The name of the dimension (axis) used for time.
#' Defaults to \code{"time"}.
#' @param outdir A character string specifying output directory where data
#' frames are written using the \code{save} statement. If omitted (defaults to
#' \code{NA}), a tidy data frame containing all data is returned.
#' @param fileprefix A character string specifying the file name prefix.
#' @param varnam The variable name(s) for which data is to be read from NetCDF
#' files.
#' @param ilon An integer specifying an individual longitude index for chunking
#' all processing and writing chunks to separate output files. If provided,
#' it overrides that the function extracts data for all longitude indices. If
#' omitted (\code{ilon = NA}), the function returns tidy data for all longitude
#' indexes.
#' @param lonnam The dimension name of longitude in the NetCDF files.
#' @param latnam The dimension name of latitude in the NetCDF files.
#' @param timenam The name of dimension variable used for timein the NetCDF
#' files. Defaults to \code{"time"}.
#' @param timedimnam The name of the dimension (axis) used for time.
#' Defaults to \code{"time"}.
#' @param ncores Number of cores for parallel execution (distributing
#' extraction of longitude slices). When set to \code{"all"}, the number of
#' cores for parallelisation is determined by \code{parallel::detectCores()}.
Expand All @@ -41,14 +41,14 @@
#'
map2tidy <- function(
nclist,
outdir = NA,
fileprefix,
varnam,
ilon = NA,
lonnam = "lon",
latnam = "lat",
timenam = "time",
timedimnam = "time",
outdir = NA,
fileprefix = NA,
ilon = NA,
ncores = 1,
single_basedate = FALSE,
fgetdate = NA,
Expand Down
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ df <- map2tidy(
nclist = list.files(paste0(here::here(), "/data-raw/"),
pattern = "demo_data_2017_month",
full.names = TRUE),
outdir = NA,
fileprefix = "demo_data_2017",
varnam = "et",
ilon = NA,
lonnam = "lon",
latnam = "lat",
timenam = "time",
Expand All @@ -41,20 +38,19 @@ df$data[[1]] |>

### Large files

When handling large files, having the complete data frame returned should be avoided to avoid memory overload. Write chunks of the data to separate files, placed in a directory as specified by the argument `outdir = NA`. The chunks will be along longitudinal bands (single index in longitude, all indices in latitude).
When handling large files, having the complete data frame returned should be avoided to avoid memory overload. Write chunks of the data to separate files, placed in a directory as specified by the argument `outdir` with file names specified by argument `fileprefix`. The chunks will be along longitudinal bands (single index in longitude, all indices in latitude).
```r
map2tidy(
nclist = list.files(paste0(here::here(), "/data-raw/"),
pattern = "demo_data_2017_month",
full.names = TRUE),
outdir = paste0(here::here(), "/data/"),
fileprefix = "demo_data_2017",
varnam = "et",
ilon = NA,
lonnam = "lon",
latnam = "lat",
timenam = "time",
timedimnam = "time",
outdir = paste0(here::here(), "/data/"),
fileprefix = "demo_data_2017",
overwrite = TRUE
)
```
Expand All @@ -67,15 +63,14 @@ map2tidy(
nclist = list.files(paste0(here::here(), "/data-raw/"),
pattern = "demo_data_2017_month",
full.names = TRUE),
outdir = paste0(here::here(), "/data/"),
fileprefix = "demo_data_2017",
varnam = "et",
ilon = NA,
lonnam = "lon",
latnam = "lat",
timenam = "time",
timedimnam = "time",
outdir = paste0(here::here(), "/data/"),
fileprefix = "demo_data_2017",
ncores = 3,
overwrite = TRUE
)
```
```
15 changes: 5 additions & 10 deletions vignettes/example.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ df <- map2tidy(
nclist = list.files(paste0(here::here(), "/data-raw/"),
pattern = "demo_data_2017_month",
full.names = TRUE),
outdir = NA,
fileprefix = "demo_data_2017",
varnam = "et",
ilon = NA,
lonnam = "lon",
latnam = "lat",
timenam = "time",
Expand All @@ -50,20 +47,19 @@ df$data[[1]] |>

### Large files

When handling large files, having the complete data frame returned should be avoided to avoid memory overload. Write chunks of the data to separate files, placed in a directory as specified by the argument `outdir = NA`. The chunks will be along longitudinal bands (single index in longitude, all indices in latitude).
When handling large files, having the complete data frame returned should be avoided to avoid memory overload. Write chunks of the data to separate files, placed in a directory as specified by the argument `outdir` with file names specified by argument `fileprefix`. The chunks will be along longitudinal bands (single index in longitude, all indices in latitude).
```{r}
map2tidy(
nclist = list.files(paste0(here::here(), "/data-raw/"),
pattern = "demo_data_2017_month",
full.names = TRUE),
outdir = paste0(here::here(), "/data/"),
fileprefix = "demo_data_2017",
varnam = "et",
ilon = NA,
lonnam = "lon",
latnam = "lat",
timenam = "time",
timedimnam = "time",
outdir = paste0(here::here(), "/data/"),
fileprefix = "demo_data_2017",
overwrite = TRUE
)
```
Expand All @@ -76,14 +72,13 @@ map2tidy(
nclist = list.files(paste0(here::here(), "/data-raw/"),
pattern = "demo_data_2017_month",
full.names = TRUE),
outdir = paste0(here::here(), "/data/"),
fileprefix = "demo_data_2017",
varnam = "et",
ilon = NA,
lonnam = "lon",
latnam = "lat",
timenam = "time",
timedimnam = "time",
outdir = paste0(here::here(), "/data/"),
fileprefix = "demo_data_2017",
ncores = 3,
overwrite = TRUE
)
Expand Down

0 comments on commit 2c3222b

Please sign in to comment.