Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find list of attached data-sets in R?

Tags:

r

detach

Is there any method in R to find out what data-sets have been attached. In my work flow i use the console and build a script. I try out the lines of code in console and once i am satisfied with the results, i add them to a script so that I can reproduce the results later. For past week i have been playing with a few data-sets. I think I attached and detached a number of them over time. But now I need to know what data-sets are current attached, so that I can detach them.

like image 877
Sam Avatar asked Feb 28 '12 15:02

Sam


People also ask

How do I get a list of datasets in R?

To get the list of available data sets in base R we can use data() but to get the list of data sets available in a package we first need to load that package then data() command shows the available data sets in that package. Also, for data sets in base R, we can use ls("package:datasets").

Where are the objects created in RStudio kept and displayed?

When you create an object, the object will appear in the environment pane of RStudio, as shown in Figure 1-2. This pane will show you all of the objects you've created since opening RStudio. Figure 1-2. The RStudio environment pane keeps track of the R objects you create.


2 Answers

Use search() to find out which objects are attached.

Since this will also tell you about all packages that are attached, you can use a regular expression to remove the packages from the search results:

Attach mtcars:

attach(mtcars)
The following object(s) are masked from 'package:ggplot2':

    mpg

Now use search() and a regexp:

attached <- search()
attached[!grepl("package", attached)]
[1] ".GlobalEnv"    "mtcars"        "tools:rstudio" "Autoloads" 
like image 57
Andrie Avatar answered Oct 08 '22 02:10

Andrie


I guess you are searching for the search() command. This should show the attached dataframes and packages you have included.

also type help(search) and check what it is doing.

like image 29
zipizip Avatar answered Oct 08 '22 02:10

zipizip