[R-pkg-devel] appropriate directory for data downloads in examples, demos and vignettes

Stachelek, Joseph jstachel at sfwmd.gov
Mon Jun 29 18:23:32 CEST 2015


Following the answer posted by 'James' at: http://stackoverflow.com/questions/12598242/global-variables-in-packages-in-r

I have the user set the data directory by editing a file (yourdatadirpath) which is then read into options() on package load.

.onLoad<-function(libname=find.package("datapkg"),pkgname="datapkg"){
options("yourdatadir"=matrix(utils::read.delim(system.file("yourdatadirpath",package="datapkg"),header=FALSE,stringsAsFactors=FALSE))[[1]][1])
}


-----Original Message-----
From: R-package-devel [mailto:r-package-devel-bounces at r-project.org] On Behalf Of Neal Fultz
Sent: Monday, June 29, 2015 12:06 PM
To: Jonathan Callahan
Cc: r-package-devel at r-project.org
Subject: Re: [R-pkg-devel] appropriate directory for data downloads in examples, demos and vignettes

I would use tempfile() instead of /tmp/. That should create a
file/directory that will get cleaned up when the R session ends, instead of
when the machine reboots. AFAIK it also works on windows.

On Mon, Jun 29, 2015 at 8:25 AM, Jonathan Callahan <
jonathan at mazamascience.com> wrote:

> Hi,
>
> The MazamaSpatialUtils
> <http://cran.r-project.org/package=MazamaSpatialUtils> package has a
> required "package state" variable which users set to specify where they
> want to store large amounts of GIS data that is being downloaded and
> converted by the package. The implementation of this follows Hadley's
> advice here:
>
> http://adv-r.had.co.nz/Environments.html#explicit-envs
>
> The functionality is implemented with package environment and getter and
> setter functions:
>
> spatialEnv <- new.env(parent = emptyenv())
> spatialEnv$dataDir <- NULL
>
>
> getSpatialDataDir <- function() {
>   if (is.null(spatialEnv$dataDir)) {
>     stop('No data directory found. Please set a data directory with
> setSpatialDataDir("YOUR_DATA_DIR").',call.=FALSE)
>   } else {
>     return(spatialEnv$dataDir)
>   }
> }
>
>
> setSpatialDataDir <- function(dataDir) {
>   old <- spatialEnv$dataDir
>   dataDir <- path.expand(dataDir)
>   tryCatch({
>     if (!file.exists(dataDir)) dir.create(dataDir)
>     spatialEnv$dataDir <- dataDir
>   }, warning = function(warn) {
>     warning("Invalid path name.")
>   }, error   = function(err) {
>     stop(paste0("Error in setSpatialDataDir(",dataDir,")."))
>   })
>   return(invisible(old))
> }
>
>
> My question is:
>
> *What is an appropriate directory to specify for vignettes (or demos or
> examples) that need to go through CRAN testing?*
>
> The R code in vignettes need to specify a directory that is writable during
> the package build process but that will also be available to users.
>
> Should we create a /tmp/<hash> directory? Would that be available on all
> systems?
>
> Alternatively,
>
> *What is an alternative to vignettes and demos for tutorial scripts that
> should not be tested upon submission to CRAN?*
>
>
> Thanks for any suggestions.
>
> Jon
>
>
> --
> Jonathan Callahan, PhD
> Mazama Science
> 206-708-5028
> mazamascience.com
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

        [[alternative HTML version deleted]]

______________________________________________
R-package-devel at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


We value your opinion. Please take a few minutes to shar...{{dropped:5}}



More information about the R-package-devel mailing list