data.cache: Retrieve data from a data cache.

Description Usage Arguments Details See Also Examples

Description

This function maintains a data cache. When called, it will see if a "fresh" data file is available. If not (i.e. the cache is "stale"), FUN will be called to retreive more up-to-date data. On systems supporting forking (e.g. Linux and Mac OS X), the refreshing of data will occur in the background and the most "fresh" data will be returned until that background process completes.

Usage

1
2
data.cache(FUN, frequency = daily, cache.dir = "cache",
  cache.name = "Cache", envir = parent.frame(), wait = FALSE, ...)

Arguments

FUN

the function used to laod the data.

frequency

how frequently should the cache expire.

cache.dir

the directory containing the cached data files.

cache.name

name of the cache.

envir

the enviroment into which data will be loaded.

wait

should the function wait until stale data is refreshed.

...

other parameters passed to FUN.

Details

The FUN parameter is required. This function should return a named list of objects. These objects will be assigned to the given environment (the calling environment by default).

There are a number of frequencies available to determine when a cached file becomes stale including: hourly, daily, weekly, monthly, yearly, nMinutes, nHours, and nDays.

It is possible to define custom frequencies. Each frequency function takes one parameter, timestamp, which has a class type of POSIXct, and returns a logical value where TRUE indicates the cache created at timestamp is stale.

See the Vignette (vignette('DataCache')) or demo (demo('WeatherCache')) for more information.

See Also

daily, hourly, weekly, monthly, yearly, nMinutes, nHours, nDays

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
library('weatherData')
loadWeatherData <- function(station_id='ALB') {
		results <- list(getDetailedWeather(station_id, Sys.Date()))
		names(results) <- paste0('weather.', station_id)
		return(results)
}
data.cache(loadWeatherData)
head(weather.ALB)

## End(Not run)

jbryer/DataCache documentation built on May 18, 2019, 7 p.m.