[R-pkg-devel] Carry over in package with multiple vignettes
It might run afoul of the "don't use attach()" rule, but attach()
seems like a good solution for this? e.g
attach(mydata)
ls("mydata")
... do stuff ...
detach(mydata)
? This assumes you don't modify the object ...
On Tue, Feb 17, 2026 at 1:41?PM Kevin R. Coombes
<kevin.r.coombes at gmail.com> wrote:
Hi,
I have an R package (RPointCloud) that contains three vignettes. Each
vignette starts by loading a different example dataset, and then calls
"ls" to show the reader what objects were loaded. It is abundantly clear
that the vignettes are all produced in the same R process. Thus, the
"ls" in the later vignettes includes a list of all objects created
during earlier vignettes. Since each vignette is really intended to be
standalone, these lists are misleading.
In an early submission of the package, I included a command at the end
of the form "rm(list = ls())", which I removed after objections from a
CRAN reviewer that this process could/would remove things that a user
already had in their workspace before they started running the vignette
themselves. So, I took those commands out.
What is the best way to ensure that objects are not carried over from
one vignette to another? I am thinking about the following:
# at the top of each vignette:
origobj <- ls()
# at the bottom of each vignette
currobj <- ls()
ourobj <- currobj[!(currobj %in% origobj)]
rm(list = ourobj
Will this procedure pass the CRAN review? Is there a better way to
accomplish this goal?
Thanks,
Kevin
______________________________________________ R-package-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel