Learn R Programming

reproducible (version 0.2.0)

preProcess: Download, Checksum, Extract files

Description

This does downloading (via downloadFile), checksumming (Checksums), and extracting from archives (extractFromArchive), plus cleaning up of input arguments (e.g., paths, function names). This is the first stage of three used in prepInputs.

Usage

preProcess(targetFile = NULL, url = NULL, archive = NULL,
  alsoExtract = NULL, destinationPath = ".", fun = NULL,
  quick = getOption("reproducible.quick"), overwrite = FALSE,
  purge = FALSE, useCache = getOption("reproducible.useCache", FALSE), ...)

Arguments

targetFile

Character string giving the path to the eventual file (raster, shapefile, csv, etc.) after downloading and extracting from a zip or tar archive. This is the file before it is passed to postProcess. Currently, the internal checksumming does not checksum the file after it is postProcessed (e.g., cropped/reprojected/masked). Using Cache around prepInputs will do a sufficient job in these cases.

url

Optional character string indicating the URL to download from. Normally, if used within a module, this url should be explicitly given as sourceURL for an expectsInput. In that case, it will use the module's checksums file to confirm that the download occurred correctly. If URL is used here, an ad hoc checksums will be created in the destinationPath. This will be used in subsequent calls to prepInputs, comparing the file on hand with the ad hoc CHECKSUMS.txt.

archive

Optional character string giving the path of an archive containing targetFile, or a vector giving a set of nested archives (e.g., c("xxx.tar", "inner.zip")). If there is/are (an) inner archive(s), but they are unknown, the function will try all until it finds the targetFile

alsoExtract

Optional character string naming files other than targetFile that must be extracted from the archive.

destinationPath

Character string of a directory in which to download and save the file that comes from url and is also where the function will look for archive or targetFile.

fun

Character string indicating the function to use to load targetFile into an R object.

quick

Logical. This is passed internally to Checksums (the quickCheck argument), and to Cache (the quick argument). This results in faster, though less robust checking of inputs. See the respective functions.

overwrite

Logical. Should downloading and all the other actions occur even if they pass the checksums or the files are all there.

purge

Logical or Integer. 0/FALSE (default) keeps existing CHECKSUMS.txt file and prepInputs will write or append to it. 1/TRUE will deleted the entire CHECKSUMS.txt file. Other options, see details.

useCache

Passed to Cache in various places. Default FALSE

...

Additional arguments passed to fun (i.e,. user supplied), postProcess and Cache. Since ... is passed to postProcess, these will ... will also be passed into the inner functions, e.g., cropInputs. See details and examples.

Value

A list with 5 elements, checkSums (the result of a Checksums after downloading), dots (cleaned up ..., including deprecated argument checks), fun (the function to be used to load the preProcessed object from disk), targetFilePath (the fully qualified path to the targetFile), and tryRasterFn (a logical whether the the targetFilePath should be loaded with raster).