Calling an expression that was created using a sample

When I want to view structures as they are called, I can usually do so with enquote

.

For an arbitrary list, d

this would be

> d <- list(a = 1, b = 2)
> enquote(d)
# quote(list(a = 1, b = 2))

      

But for an object created with a sample it is different. sample

does not appear in the quoted call.

> m <- matrix(sample(2))
> enquote(m)
# quote(c(2L, 1L))

      

Is there a way to show the expression / expression created m

to appear sample

? So the result will be something like

quote(matrix(sample(2))

      


Update: . Simon's answer is below, but I'd really like to know if I can get an answer that doesn't require use substitute

to create a matrix m

.

+3


source to share


1 answer


I'm not 100% sure if this serves your purpose, but you can try defining the expression with substitute

before evaluating it to create m

(no quote

though ...):

xpr <- substitute(matrix(sample(2)))
m <- eval(xpr)

      

Result:



> m
     [,1]
[1,]    2
[2,]    1
> xpr
matrix(sample(2))

      

Hooray!

+2


source







All Articles