View source: R/fexample_data.R
| f_example_data | R Documentation |
Convenience accessor for the example data files shipped with the package
(used throughout the rfriend course). With no arguments it lists the available
files. Given a file name it returns the full path to the installed file,
ready to pass to a reader such as read.csv,
read_excel or f_open_file. Optionally it
copies the file to a destination so learners can practise importing a file
that sits in their own working directory.
f_example_data(file = NULL, dest = NULL, overwrite = FALSE)
file |
Character string: the name of an example file (e.g.
|
dest |
Optional path. If supplied, the example file is copied there and
the path of the copy is returned (invisibly). |
overwrite |
Logical; passed to |
The files live in the package's extdata directory and are located
with system.file. Because system.file() returns
an empty string for a missing file, this function checks explicitly and
fails with an informative error listing the valid names, rather than letting
a later reader fail on an empty path.
If file is NULL, a character vector of available file names.
If file is supplied and dest is NULL, the full path to
the installed example file. If dest is supplied, the path to the
copied file (returned invisibly).
Sander H. van Delden plantmind@proton.me
# List the available example files
f_example_data()
# Get the path to one of them, then read it
path <- f_example_data("plant_trial_raw.csv")
df <- read.csv(path)
## Not run:
# Copy a file into the current working directory to import it "from disk"
f_example_data("plant_trial_raw.xlsx", dest = getwd())
# Open an example file in its default application
f_open_file(f_example_data("plant_trial_raw.xlsx"))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.