Load a pre-generated R binary data file from either a local directory or a remote URL.
loadDataFile(
filename = NULL,
dataUrl = NULL,
dataDir = NULL,
priority = c("dataDir", "dataUrl")
)Object loaded from the .rda file.
This function is intended for use by package-level *_load() helper
functions. It allows locally cached data files to be used when available,
avoiding unnecessary internet access.
If both dataDir and dataUrl are provided, priority determines which
source is tried first. If loading from the first source fails, the other
source is used as a fallback.
The .rda file must contain exactly one object. A file containing several
objects generates an error.
Only load data from sources you trust. Loading an .rda file restores
arbitrary R objects, which can include functions and other code, so dataUrl
(and dataDir) should point to locations you control.
if (FALSE) { # \dontrun{
filename <- "USCensusStates_02.rda"
dataDir <- "~/Data/Spatial"
dataUrl <- "http://data.mazamascience.com/MazamaSpatialUtils/Spatial_0.8"
# Load local file
USCensusStates <- loadDataFile(filename, dataDir = dataDir)
# Load remote file
USCensusStates <- loadDataFile(filename, dataUrl = dataUrl)
# Load local file with remote file as backup
USCensusStates <- loadDataFile(
filename,
dataDir = dataDir,
dataUrl = dataUrl,
priority = "dataDir"
)
# Load remote file with local file as backup
USCensusStates <- loadDataFile(
filename,
dataDir = dataDir,
dataUrl = dataUrl,
priority = "dataUrl"
)
} # }