This may be a dumb question. If the names of variable to be extracted are in 
the file, should there be a function that does not extract the data but simply 
returns a list of some sort of the names of variables that would be created if 
it is extracted? 

It would then be simple enough to gather the names and perhaps verify they are 
now in the environment and tell the user what to expect.

And, of course, I can imagine an alternative function that extracts the data 
and ALSO (perhaps only on request) creates another named variable like 
".Last_extraction" containing the names of the other variables it created.

-----Original Message-----
From: R-package-devel <[email protected]> On Behalf Of 
Kevin R. Coombes
Sent: Tuesday, February 17, 2026 2:29 PM
To: [email protected]; Ben Bolker <[email protected]>
Cc: R Package Development <[email protected]>
Subject: Re: [R-pkg-devel] Carry over in package with multiple vignettes

Hi Marcel,

It might be better to combine this idea with Ben Bolker's suggestion. 
(Using everything within a new environment means adding the appropriate 
references to dig into that environment every time I use one of the 
objects, meaning I would have to carefully rewrite the whole vignette.) 
Something like

```{r vigdata}
nenv <- new.env()
data("cytof", envir = nenv)
ls(nenv)
attach(nenv)
```
...do stuff...

```{r cleanup}
detach(nenv)
rm(nenv)
```

Thanks,
     Kevin

On 2/17/2026 2:09 PM, Marcel Ramos Pérez wrote:
> Hi Kevin,
>
> It would be more preferable to just use the names of the datasets 
> without having to do `ls()`.
>
> Otherwise, have you tried to load your data into an empty environment 
> per vignette and
> then do `ls()` on that environment?
>
> For example,
>
> ```{r, echo=FALSE}
> vig_data1 <- new.env(parent = emptyenv())
> data(..., package = "RPointCloud", envir = vig_data1)
> ls(envir = vig_data1)
> ```
>
> and show the user a non-evaluated chunk
>
> ```{r,eval=FALSE}
> ls()
> ```
>
> Best regards,
> Marcel
>
> On 2/17/26 1:47 PM, Ben Bolker wrote:
>> * External Sender - Proceed Cautiously with Links and Attachments. *
>>
>>       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
>> <[email protected]> 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
>>>
>>> ______________________________________________
>>> [email protected] mailing list
>>> https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-package-devel__;!!LRXxDv2l!TCoohdCCt53OwwimPx9i6UhVDPy6NpUMzn-z9-F1sE_GnHi5m8hgN1THdXv-vWXA0ooLFOUPO2-QzRgao6mHYQ$
>>>  
>>>
>> ______________________________________________
>> [email protected] mailing list
>> https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-package-devel__;!!LRXxDv2l!TCoohdCCt53OwwimPx9i6UhVDPy6NpUMzn-z9-F1sE_GnHi5m8hgN1THdXv-vWXA0ooLFOUPO2-QzRgao6mHYQ$
>>  
>>

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to