Title: | Reproducible Data Embedding |
---|---|
Description: | Allows caching of raw data directly in R code. This allows R scripts and R Notebooks to be shared and re-run on a machine without access to the original data. Cached data is encoded into an ASCII string that can be pasted into R code. When the code is run, the data is automatically loaded from the cached version if the original data file is unavailable. Works best for small datasets (a few hundred observations). |
Authors: | Stefan Kloppenborg [aut, cre] |
Maintainer: | Stefan Kloppenborg <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0.9003 |
Built: | 2025-01-24 02:53:36 UTC |
Source: | https://github.com/kloppen/rde |
copy_rde_var
is intended to work with load_rde_var
.
The normal workflow would use copy_rde_var
to copy a variable to
the clipboard and then paste it in to the third argument of
load_rde_var
.
copy_rde_var(var, line.width = 80L, no.clipboard = FALSE)
copy_rde_var(var, line.width = 80L, no.clipboard = FALSE)
var |
the variable to copy |
line.width |
the desired width of lines of text (-1 for no line breaks) |
no.clipboard |
the default is FALSE. Indicates that you want the function to return the string that would have been copied to the clipboard without actually copying to the clipboard. This option is mainly used for testing purposes. Normal users will not use it. |
The variable in the argument var
is first saved using
saveRDS
. Then the saved variable is compressed using
bzip2 compression. Next, the compressed data is base 64 encoded into
a character string. Next, that string is prepended with a code that
indicates the version of this package. The prepended code (currently
'rde1' allows for future changes while providing backwards compatibility).
Finally, the string is optionally broken up into lines of width
line.width
. Whitespace and line breaks are ignored by
load_rde_var
.
On X11 systems (e.g. Linux), external software is required in order to access the clipboard. Either 'xsel' or 'xclip' is required. Installation of this software will depend on the installation that you use, but on Ubuntu/Debian, 'sudo apt-get install xsel' will probably work.
On Windows and OSX, no additional software is required.
None (or string if no.clipboard=TRUE)
copy_rde_var(iris)
copy_rde_var(iris)
load_rde_var
attempts to execute the code in load.fcn
. If
that succeeds, then the return value of that code is returned by
load_rde_var
. Otherwise, the value stored in cache
is
returned. cache
must contain an encoded copy of the value produced
by the function copy_rde_var
. Optionally, you can force
the use of the cached data by setting use.cache = TRUE
.
load_rde_var(use.cache = FALSE, load.fcn, cache)
load_rde_var(use.cache = FALSE, load.fcn, cache)
use.cache |
boolean to force the use of cached data |
load.fcn |
code to load the data from its original source |
cache |
a cached copy of the data |
This package is intended for small datasets. A copy of the data is encoded as a string (using base64 encoding, after compressing the data) and that string is copied into your code. Even though the data is compressed, the encoded string can still be quite long. If your data is more than a few hundred observations, this package probably isn't for you.
load.fcn
must contain executable R code. Unless that code is a
single expression, normally it would be enclosed in a pair of braces.
cache
must be a string that was originally produced by
copy_rde_var
. See the documentation for that function for
more details about the format of this string.
If the code in load.fcn
fails, then a message is produced to
indicate that the failure and the data encoded in cache
is returned
instead. This would occur if you share you code with someone who does
not have access to the data that you're loading in your code.
If use.cache = TRUE
, the code in load.fcn
is ignored and
the data is loaded from the encoded string cache
. This can be useful
if it takes a very long time obtain the data and you re-run your code
often.
If the value produced by the code in load.fcn
does not match the
value encoded in cache
, then a warning is produced to indicate
that there is a mismatch.
The data, either loaded using load.fcn, if possible, or from cache if that fails.
load_rde_var(use.cache = FALSE, { head(iris, 3) }, " rde1QlpoOTFBWSZTWbGO254AAKT/5P//XAAAAQAAwARIwC/n3YBAAAAwACYFAbAA7IhKIm lPaU3oaRqekyaDTQNPJP1MhDAaA0AAGmg0A0AaBIokNGgAAAAAANMYUzuJyxRYUJWNnsC1 tgiccpLFvZTHhARK1KFQ1z25bNBCC+0pWKgEnGEzpxVaihSiTBL2j6RRFchjamGBFpBMwN bAHwgEGosCEGYBoztHPFUVjGcDz3qu9p4cb8rVyVfHmR5S3bWXfDDnTnyJDJh0iMIpionY lfq1FwK/IvzsuBsOmuZNGtpp7oWrW4upNNGDiL2E9T6iY2RFqabO9/r9oiN6p/YIdV1FPP ISLqVP4u5IpwoSFjHbc8A= ")
load_rde_var(use.cache = FALSE, { head(iris, 3) }, " rde1QlpoOTFBWSZTWbGO254AAKT/5P//XAAAAQAAwARIwC/n3YBAAAAwACYFAbAA7IhKIm lPaU3oaRqekyaDTQNPJP1MhDAaA0AAGmg0A0AaBIokNGgAAAAAANMYUzuJyxRYUJWNnsC1 tgiccpLFvZTHhARK1KFQ1z25bNBCC+0pWKgEnGEzpxVaihSiTBL2j6RRFchjamGBFpBMwN bAHwgEGosCEGYBoztHPFUVjGcDz3qu9p4cb8rVyVfHmR5S3bWXfDDnTnyJDJh0iMIpionY lfq1FwK/IvzsuBsOmuZNGtpp7oWrW4upNNGDiL2E9T6iY2RFqabO9/r9oiN6p/YIdV1FPP ISLqVP4u5IpwoSFjHbc8A= ")