Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using R package data in function without loading it

Tags:

r

Does anyone know of a way (creative hack or otherwise) that data from an R package can be utilized inside a function without actually loading it to the environment?

As a simple example:

 plot.sepals <- function() {
     data(iris);
     plot(Sepal.Length ~ Petal.Length, data=iris);
 }

You'll notice when you run the example that the iris dataset gets loaded. This is precisely what I wish to avoid. I'd like to use the data but not have it loaded to an environment.

Thanks for any help or ideas.

like image 774
code_cowboy Avatar asked Sep 13 '25 09:09

code_cowboy


1 Answers

I'm still not allowed to comment yet, but I think that @user3293236 answered your question as I understand it.

You mean like this?

plot.sepals <- function() { 
               plot(Sepal.Length ~ Petal.Length, data=datasets::iris) }
like image 188
MVWyck Avatar answered Sep 16 '25 09:09

MVWyck