Learn R Programming

MazamaCoreUtils (version 0.5.3)

loadDataFile: Load R data from URL or local file

Description

Loads pre-generated R binary (".rda") files from a URL or a local directory. This function is intended to be called by other ~_load() functions and can remove internet latencies when local versions of data are available.

If both dataUrl and dataDir are provided, an attempt will be made to load data from the source specified by priority with the other source used as a backup.

Usage

loadDataFile(
  filename = NULL,
  dataUrl = NULL,
  dataDir = NULL,
  priority = c("dataDir", "dataUrl")
)

Value

A data object.

Arguments

filename

Name of the R data file to be loaded.

dataUrl

Remote URL directory for data files.

dataDir

Local disk directory containing data files.

priority

First data source to attempt if both are supplied.

Examples

Run this code
if (FALSE) {
library(MazamaCoreUtils)

filename = "USCensusStates_02.rda"
dir = "~/Data/Spatial"
url = "http://data.mazamascience.com/MazamaSpatialUtils/Spatial_0.8"

# Load local file
USCensusStates = loadDataFile(filename, dataDir = dir)

# Load remote file
USCensusStates = loadDataFile(filename, dataUrl = url)

# Load local file with remote file as backup
USCensusStates =
  loadDataFile(filename, dataDir = dir, dataUrl = url, priority = "dataDir")

# Load remote file with local file as backup
USCensusStates =
  loadDataFile(filename, dataDir = dir, dataUrl = url, priority = "dataUrl")

}

Run the code above in your browser using DataLab