Save the object (dataset/toc/DSD) to cache
put_eurostat_cache(
obj,
oname,
update_cache = FALSE,
cache_dir = NULL,
compress_file = TRUE
)
an object (toc, dataset, DSD)
a character string with the name of the object to reference later in the cache
a logical with a default value FALSE
, whether to update the cache. In this case the existing value in the cache is overwritten. Can be set also with options(restatapi_update=TRUE)
a path to a cache directory. The default is NULL
, in this case the object is saved in the memory (in the '.restatapi_env'). Otherwise if the cache_dir
directory does not exist it saves in the 'restatapi' directory under the temporary directory from tempdir()
. Directory can also be set with options(restatapi_cache_dir=...)
.
a logical whether to compress the RDS-file in caching. Default is TRUE
.
The function returns the place where the object was cached: either it creates an the object in the memory ('.restatapi_env') or creates an RDS-file.
Saves a given object in cache. This can be the memory .restatapi_env
or on the hards disk. If the given cache_dir
does not exist then the file is saved in the R temp directory (tempdir()
). If the file or object with the oname
exists in the cache, then the object is not cached.
dt<-data.frame(txt=c("a","b","c"),nr=c(1,2,3))
put_eurostat_cache(dt,"teszt")
#> [1] "in memory ('teszt' in '.restatapi_env')"
get("teszt",envir=restatapi::.restatapi_env)
#> txt nr
#> 1 a 1
#> 2 b 2
#> 3 c 3
put_eurostat_cache(dt,"teszt",cache_dir=tempdir())
#> [1] "in the file /tmp/Rtmp7EeCja/teszt.rds"
readRDS(file.path(tempdir(),"teszt.rds"))
#> txt nr
#> 1 a 1
#> 2 b 2
#> 3 c 3
clean_restatapi_cache(cache_dir=tempdir())