Learn R Programming

MaddisonData (version 1.0.2)

path_package2: Construct a path to a location within an installed or development package

Description

path_package2 returns a character vector of matches to target. It differs from system.file() in that it supports searching for a target file or folder possibly in subdirs of the working directory or in nparents of its parents.

Usage

path_package2(
  target,
  package = NULL,
  nparents = 1,
  subdirs = c("extdata", paste("inst", "extdata", sep = .Platform$file.sep))
)

Value

a character vector with an attribute searched giving the full paths of all directories searched for target.

Arguments

target

A regular expression describing the file of folder desired.

package

Name of the package to in which to search. If NULL, search in the working directory. Otherwise search in system.file(package).

nparents

integer indicate the number of parents of the working directory in which to search; default = 1.

subdirs

= c('extdata', paste('inst','extdata', sep=.Platform$file.sep))

Details

This works in a vignette searching for a target that could be in the vignettes directory of its parent package or in the package directory or in, e.g., one of subdirs = c('extdata', paste('inst', 'extdata', sep=.Platform$file.sep)).

Returns the full path to match(s) if found and a character vector of length 0 if no matches are found. The returned object also has a searched attribute being a character vector of the directories searched.

This was inspired by a desire to share with others a vignette describing how to create data objects from a file that could not itself be shared on CRAN. This is not easy, because the working director available to code in a vignette changes depending on how that code is run.

path_package2 allows the user to store the target locally, e.g., in inst/extdata but include it in .gitignore to prevent it from leaving the local computer. The vignette then decides what to do after calling path_package2() based on the length of the the object returned.

Examples

Run this code
# search for a file matching a regular expression
path_package2('^mpd.*xlsx$') 
# search only in the working directory
path_package2('^mpd.*xlsx$', nparents=0, subdirs=character(0)) 

Run the code above in your browser using DataLab