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

Paul Gilbert pgilbert902 at gmail.com
Mon Jun 29 18:22:53 CEST 2015


Regarding alternative places for scripts, you can add a directory (eg 
inst/testLocalScripts) and then with a recently added R CMD feature you 
can do

  R CMD check --test-dir=inst/testLocalScripts your-package.tar.gz

This will not (automatically) be checked on CRAN. Beware that you also 
need to run R CMD check without this option to run your regular tests.

Paul


On 06/29/2015 11:25 AM, Jonathan Callahan 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
>
>



More information about the R-package-devel mailing list