| rp.datalink | R Documentation |
Links to specific remote datasets are provided. These can be read from the source locations or downloaded to a local directory for convenience.
rp.datalink(name, action = "retrieve filename")
name |
When |
action |
a character string taking the values "set local directory", "download" or "retrieve filename". The actions performed by these settings are indicated in the description of the |
Calling the function with no arguments, as rp.datalink(), will print the dataset names, the file extensions and the remote link.
When action = "retrieve filename" but the file has not been downloaded to a local directory, the file is downloaded to a temporary file and the name of this temporary file is returned.
The specification of the local directory can be removed by setting the name argument to NULL.
The file associated with 'name' can be a zip file, in which case the unz function can be used to locate the specific file of interest. The Examples below illustrate this. Some functions to read data require a specific path to the file of interest, rather than a connection. In this case, the unzip function can be used to unzip the files to a temporary (using tempdir) or other specified directory first.
If the function is called with no arguments, the dataset names, the file extensions and the remote link re returned in a dataframe. If action = "set local directory", the name of the local directory is returned. When action = "download", the names of the local files created are returned. When action = "retrieve filename", the location of the specified dataset is returned.
## Not run:
rp.datalink()
rp.datalink("~/Desktop/temp", "set local directory")
rp.datalink("global_temperature")
# Reading from a file within a zip file
zfile <- rp.datalink("children_services")
dirname <- "Data and Code CSRR Strand 3 - August 2023 Update"
path <- unz(zfile, paste(dirname, "Example_Indicator_CSR.csv", sep = "/"))
if (!requireNamespace("readr", quietly = TRUE))
indicator <- read_csv(path, skip = 6, col_names = c("LA", 2011:2021))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.