literal function

it may look like a simple and basic question. I’ve been studying r for a couple of months now, and it seems to me that I cannot find the function I'm looking for. I don’t even know how to look for it ... from the ideas of search strings.

I know that there is a function to get the definition of a variable more than its contents. I explain myself ...

> x <- c(4:6,5:9)
> x  # This will return the contents of x...  4,5,6,5,6,7,8,9.

> the.function.i.m.looking.for(x)  # would return:
> c(4:6,5:9)

Does anyone remember this feature? Thank.

+3
source share
3 answers

dput- this is what you are. On the help page: "Writes an ASCII text representation of an R object to a file or connection, or uses it to recreate the object."

> x <- c(4:6,5:9)
dput(x)
c(4L, 5L, 6L, 5L, 6L, 7L, 8L, 9L)

> x2 <-  c(4L, 5L, 6L, 5L, 6L, 7L, 8L, 9L)
> all.equal(x, x2)
[1] TRUE
+5
source

dput(x) brings you closer:

R> dput(x)
c(4L, 5L, 6L, 5L, 6L, 7L, 8L, 9L)

Or, if the character representation is enough, then the idiom may be enough deparse(substitute()):

foo <- function(x) {
    deparse(substitute(x))
}

:

R> foo(c(4:6,5:9))
[1] "c(4:6, 5:9)"

R> foo(x)
[1] "x"
+4

, , dput() :

x <- c(4:6,5:9)
dput(x)
c(4L, 5L, 6L, 5L, 6L, 7L, 8L, 9L)
+3
source

All Articles