I'm writing documentation for my R package using vignettes (which will be embedded in a pkgdown website.
My question is :
if I create an R object in a chunk within a first "aa" vignette.
myobject <- mypkg::myfct()
How to reuse this object in a second vignette called "bb"?
verif <- myobject[myfilters,]
I get this error : myobject not found
CodePudding user response:
This doesn't seem like a good idea. You can save this data in an internal RDA file, and load it in the second vignette. See Chapter 14 External data, R Pakcages.
So you'd have to:
- Create a
data_raw
folder, and have a script that creates this object, then saves it. This is facilitated byusethis::use_data_raw
, with like "myfct_example". - Then, at the bottom of this script in
data_raw
ensure thatinternal = TRUE
; This will save the object inR/sysdata.rda
, instead ofdata/myfct_example
(if you call that object that). - Ensure that you run the
data_raw/myfct_example
script every time you changemyfct_example
, so the new version get stored inR/sysdata.rda
. - In both vignettes, you'll have this data object available, by
mypkg:::myfct_example
.