Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What class of objects are in the environment ? (R)

I wish to know what type of objects I've got in my environment.

I can show who is there like this:

ls()

But running something like

sapply(ls(), class)

Would (obviously) not tell us what type (class) of objects we are having (function, numeric, factor and so on...)

using

ls.str()

Will tell me what class my objects are, but I won't be able to (for example) ask for all the objects which are factors/data.frame/functions - and so on.

I can capture.output of ls.str(), but probably there is a smarter way - any idea what it is?

like image 646
Tal Galili Avatar asked Jan 20 '26 14:01

Tal Galili


1 Answers

This should do the trick:

sapply(ls(), function(x){class(get(x))})
like image 71
nico Avatar answered Jan 22 '26 07:01

nico