0
 ls()

in my environment will give me the list of all objects. But I have generated vectors, for which if I run attributes(object) I get $dim. Is there a way to select the object with this attributes? I had a look to rlist package without success. thanks.

IRT
  • 209
  • 2
  • 11
  • I've used the function in Dirk's post: https://stackoverflow.com/questions/1358003/tricks-to-manage-the-available-memory-in-an-r-session. It doesn't necessarily filter based on object type/class, but it does clearly show what objects have the `dim` attribute. – r2evans Oct 26 '18 at 15:02

1 Answers1

2

If you want to select all objects with a dim attribute, then you can do something like this ...

m <- matrix(0, 2, 2)  # has a dim attribute
v <- 1:5              # does not have a dim attribute

Filter(function(x) !is.null(dim(x)), as.list(.GlobalEnv))
# $m
#      [,1] [,2]
# [1,]    0    0
# [2,]    0    0

Since a call to dim will return NULL for objects with no dimension attribute, we ask for the objects that do not return NULL and filter them out of the environment object list.

Rich Scriven
  • 97,041
  • 11
  • 181
  • 245