Learn R Programming

reproducible

A set of tools for R that enhance reproducibility for data analytics and forecasting. This package aims at making high-level, robust, machine and OS independent tools for making deeply reproducible and reusable content in R. The suggested package geodata can be installed from the repository (https://PredictiveEcology.r-universe.dev).

News

See updates from latest CRAN and development versions. Note that versions 2.0.0 and later are not compatible with previous versions. The current version can be much faster and creates smaller repository files (each with specific options set using Suggests packages) and allows for different (e.g., RPostgres backends for the database^1 -- not the saved files, however; these are still saved locally).

Reproducible workflows

A reproducible workflow is a series of code steps (e.g., in a script) that, when run, produce the same output from the same inputs every time. The big challenge with such a workflow is that many steps are so time consuming that a scientist tends to not re-run each step every time. After many months of work, it is often unclear if the code will actually function from the start. Is the original dataset still there? Have the packages that were used been updated? Are some of the steps missing because there was some "point and clicking"?

The best way to maintain reproducibility is to have all the code re-run all the time. That way, errors are detected early and can be fixed. The challenge is how to make all the steps fast enough that it becomes convenient to re-run everything from scratch each time.

Cache

Caching is the principle tool to achieve this reproducible work-flow. There are many existing tools that support some notion of caching. The main tool here, Cache, can be nested hierarchically, becoming very powerful for the data science developer who is regularly working at many levels of an analysis.

rnorm(1) # give a random number
Cache(rnorm, 1) # generates a random number
Cache(rnorm, 1) # recovers the previous random number because call is identical

prepInputs

A common data problem is starting from a raw (spatial) dataset and getting it into shape for an analysis. Often, copies of a dataset are haphazardly placed in ad hoc local file systems. This makes it particularly difficult to share the workflow. The solution to this is use a canonical location (e.g., cloud storage, permalink to original data provider, etc.) and use tools that are smart enough to download only once.

Get a geospatial dataset. It will be checksummed (locally), meaning if the file is already in place locally, it will not download it again.

# Using dlFun -- a custom download function -- passed to preProcess
test1 <- prepInputs(targetFile = "GADM_2.8_LUX_adm0.rds", # must specify currently
                    dlFun = "raster::getData", name = "GADM", country = "LUX", level = 0,
                    path = dPath)

Cache with prepInputs

Putting these tools together allows for very rich data flows. For example, with prepInputs and using the fun argument or passing a studyArea, a raw dataset can be downloaded, loaded into R, and post processed -- all potentially very time consuming steps resulting in a clean, often much smaller dataset. Wrapping all these with a Cache can make it very quick.

test1 <- Cache(prepInputs, targetFile = "GADM_2.8_LUX_adm0.rds", # must specify currently
                    dlFun = "raster::getData", name = "GADM", country = "LUX", level = 0,
                    path = dPath)

See vignettes and help files for many more real-world examples.

Installation

Current release (on CRAN)

Install from CRAN:

install.packages("reproducible")

Install from GitHub:

#install.packages("devtools")
library("devtools")
install_github("PredictiveEcology/reproducible", dependencies = TRUE) 

Development version

Install from GitHub:

#install.packages("devtools")
library("devtools")
install_github("PredictiveEcology/reproducible", ref = "development", dependencies = TRUE) 

Contributions

Please see CONTRIBUTING.md for information on how to contribute to this project.

Copy Link

Version

Install

install.packages('reproducible')

Monthly Downloads

1,406

Version

3.2.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Eliot J B

Last Published

August 25th, 2026

Functions in reproducible (3.2.1)

dlGeneric

Download file from generic source url
determineFilename

Determine filename, either automatically or manually
detectActiveCores

Count Active Threads Based on CPU Usage
copySingleFile

Copy a file using robocopy on Windows and rsync on Linux/macOS
convertPaths

Change the absolute path of a file
.debugCache

Attach debug info to return for Cache
.applyUrlRemap

Apply the user-supplied URL remap hook
.digest

Calculate the hashes of multiple files
fixErrors

Do some minor error fixing
dlGoogle

Download file from Google Drive
.objSizeWithTry

lobstr::obj_size with a try to address issue #72
.probeRange

Probe a URL for size and HTTP Range support
.file.move

Move a file to a new location -- Defunct -- use hardLinkOrCopy
.isMemoised

Evaluate whether a cacheId is memoised
.formatDuration

Format a duration in seconds as a compact human-readable string
.formalsNotInCurrentDots

Identify which formals to a function are not in the current ...
.remapUrlEarly

Resolve and remap a URL early, before the COG fast-path
.dlGooglePublic

Download a public Google Drive file without authentication
.expandAlsoExtractPatterns

Expand regex patterns in alsoExtract against a known list of archive files.
.parallelRangedDownload

Download a file in parallel using HTTP Range requests
.useParallelDownload

Decide whether to use the parallel ranged download path
.removeCacheAtts

Remove attributes that are highly varying
.whereInStack

Search for objects in the call stack
.wrap

Deal with class for saving to and loading from Cache or Disk
downloadRemote

Download a remote file
.urlRemapFn

Resolve the reproducible.urlRemap option to a remap function
.requireNamespace

Provide standard messaging for missing package dependencies
downloadFile

A wrapper around a set of downloading functions
.sortDotsUnderscoreFirst

Exported generics and methods
gdalProject

3-Step postProcess sequence for SpatRasters using gdalwarp
extractFromArchive

Extract files from archive
fixErrorsIn

Fix common errors in GIS layers, using terra
.dumpPreDigest

Dump the element-by-element preDigest of a Cache() call
.isGridded

Some spatial helper functions
harmonizeCall

Harmonize all forms of call
.grepSysCalls

Grep system calls
isLinux

Test whether system is Linux specifically
isInteractive

Alternative to interactive() for unit testing
internetExists

listGoogleDriveFolder

List a Google Drive folder, using a mirror listing when remapped
keepOrigGeom

Keep original geometries of sf objects
listNamed

Create a list with names from object names
makeUrlRemap

Build a URL remap function from a manifest
isUpdated

Has a cached object has been updated?
guessAtTarget

Try to pick a file to load
linkOrCopy

Hardlink, symlink, or copy a file
loadFile

Load a file from the cache
.listFilesInArchive

List files in either a .zip or or .tar file
isUnix

Test whether system is unix-alike (macOS, Linux, BSD, ...)
isWindows

Test whether system is Windows
mergeShownCacheCloud

Fold cloud cache metadata into a local showCache result for showSimilar
.message

The reproducible package environments
paddedFloatToChar

Convert numeric to character with padding
mergeCache

Merge two cache repositories together
normPath

Normalize file paths
matchCall2

Remove quote and determine if call uses ...
movedCache

Deal with moved cache issues
numCoresToUse

Estimate Number of CPU Cores to Use for Parallel Processing
objSize

Wrapper around lobstr::obj_size
messageDF

Use message with a consistent use of verbose
preProcessParams

Download, checksum, extract files
postProcessTo

Transform a GIS dataset so it has the properties (extent, projection, mask) of another
postProcess

Generic function to post process objects
prepInputsLog

URL access log for prepInputs / preProcess
postProcessInputsSuperseded

Superseded postProcess input functions
.prepareFileBackedRaster

Copy the file-backing of a file-backed Raster* object
prepInputsCOG

Fast spatial subsetting of Cloud Optimized GeoTiff (COG) files
.prefix

Add a prefix or suffix to the basename part of a file path
prepInputs

Download and optionally post-process files
prepInputsWithTiles

Alternative to prepInputs that can use Spatial Tiles stored locally or on Google Drive
.purge

Purge individual line items from checksums file
rasterRead

A helper to getOption("reproducible.rasterRead")
purgeChecksums

Purge the checksums of a single file
reproducible-package

The reproducible package
prepopulateCacheAsync

Pre-populate the in-memory showCache cache for a given cachePath
remapFilenames

Remap file names
.robustDigest

Create reproducible digests of objects in R
reproducibleOptions

reproducible options
retry

A wrapper around try that retries on failure
getRelative

Relative paths
minFn

Get min or maximum value of a (Spat)Raster
studyAreaName

Get a unique name for a given study area
tempfile2

Make a temporary file in a temporary (sub-)directory
set.randomseed

Set seed with a random value using Sys.time()
searchFull

Search up the full scope for functions
tempdir2

Make a temporary (sub-)directory
testForArchiveExtract

Returns unrar path and creates a shortcut as .systemArchivePath. Was not incorporated in previous function so it can be used in the tests.
.setSubAttrInList

Set subattributes within a list by reference
saveToCache

Save an object to Cache
showCacheCloud

List and read all cloud cache metadata (dbFile) files
unrarPath

The known path for unrar or 7z
writeFuture

Write to cache repository, using future::future (defunct)
showCache

Examining and modifying the cache
usesPointer

Does an object use a pointer?
Path-class

Coerce a character string to a class "Path"
Filenames

Return the filename(s) from a Raster* object
createCache

Low-level functions to create and work with a cache
CacheDigest

The exact digest function that Cache uses
.addTagsRepo

Add a Tag to a Cached Object in the Repository
Copy

Recursive copying of nested environments, and other "hard to copy" objects
archiveExtractBinary

Tests if unrar or 7zip exist
Checksums

Calculate checksum
CacheGeo

Cache-like function for spatial domains
Cache

Saves a wide variety function call outputs to disk and optionally RAM, for recovery later
cloudDownload

Download from cloud, if necessary
checkRelative

An alternative to basename and dirname when there are sub-folders
convertCallToCommonFormat

Convert all ways of calling a function into canonical form, including defaults
basename2

A version of base::basename that is NULL resistant
checkAndMakeCloudFolderID

Check for presence of checkFolderID (for Cache(useCloud))
checkPath

Check directory path
compareNA

NA-aware comparison of two vectors
cacheId

Extract the cache id of an object
cloudUploadFromCache

Upload a file to cloud directly from local cachePath
assessDataType

Assess the appropriate raster layer data type