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.
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").
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.
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With