R equivalent to the Python function "dir"?

Sigve Karolius

Is there a function in R that can tell me the attributes of a given object (or class)?

Consider the "dir" function in python when passed the file class:

>>> dir(file)
['__class__', '__delattr__', '__doc__', '__enter__', '__exit__', 
 '__format__', '__getattribute__', '__hash__', '__init__', '__iter__',
 '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
 '__sizeof__', '__str__', '__subclasshook__', 'close', 'closed',
 'encoding', 'errors', 'fileno', 'flush', 'isatty', 'mode', 'name',
 'newlines', 'next', 'read', 'readinto', 'readline', 'readlines',
 'seek', 'soft space', 'tell', 'truncate', 'write', 'writelines',
 'xreadlines']

Maybe there is an equivalent of type as well(?)

>>> type(1)
<type 'int'>
Matthew Plourde

R makes several different object oriented systems available to you, so if you don't know what species of object you're dealing with, you'll first need to determine whether it is one of S3, S4, or RC. Use isS4(x) and is(x, 'refClass') for this. If it's not S4 and not RC, it's S3. See Hadley's Advanced R chapter on object oriented programming for more information.

For S3 and S4 objects there are several functions you need to call to get information equivalent to Python's dir. All of these methods will require you to supply the name of the class of the object as an argument, which you can determine with the class function.

For methods, use methods(class=class(x)) for S3 objects and showMethods(class=class(x)) for S4 objects. To reveal "attribute" names/values, use attributes(x) for S3 objects and getSlots(class(x)) for S4 objects. Note, getSlots will only show the slot names and types, not their values. To access the values, you'll have to use slot, but these values should also print when you simply print the object to the console.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Equivalent of Python's dir function in PHP

From Dev

Python dir equivalent in perl?

From Dev

Python equivalent of R "split"-function

From Dev

Is there an equivalent of python `dir` for haskell ghci?

From Dev

Is there an equivalent of Python's dir() in Elixir

From Dev

Is there an equivalent of Python's dir() in Elixir

From Dev

Is there a Python equivalent to R's sample() function?

From Dev

Python equivalent of R's head and tail function

From Dev

Python numpy or pandas equivalent of the R function sweep()

From Dev

Python's equivalent for R's dput() function

From Dev

Python equivalent of R apply with anonymous function

From Dev

Equivalent of R function 'ave' in Python Pandas

From Dev

Equivalent of Python's dir() in the node REPL?

From Dev

Equivalent of Python's dir() in the node REPL?

From Dev

Equivalent R function for Matlab

From Dev

Equivalent R function for Matlab

From Dev

Browser() equivalent function in Python

From Dev

Is there a Python equivalent to the mahalanobis() function in R? If not, how can I implement it?

From Java

python equivalent of R table

From Dev

Python equivalent of the R operator "%in%"

From Dev

Equivalent of source() of R in Python

From Dev

Equivalent of "table" of R in python

From Dev

R equivalent of the Matlab spy function

From Dev

Mod() function in R equivalent for MatLab?

From Dev

The equivalent function of Matlab imfilter in Python

From Dev

Matlab importdata() function equivalent in Python

From Dev

Is there a Swift equivalent to the 'Filter' function in Python?

From Dev

Equivalent matlab damp function for Python

From Dev

Equivalent ruby load function in python

Related Related

HotTag

Archive