user7417
user7417

Reputation: 1581

How to address an R-variable that stores an object of class 'name'?

In a larger R-Script I have to address the content of a character variable that itself is stored within a variable of class name. In the following small example, how do I have to address B to see the content of A (thus "A") and not just the name (thus A)?

> A <- "A"
> B <- as.name(A)
> B
A

Upvotes: 2

Views: 63

Answers (1)

akrun
akrun

Reputation: 887991

We can use get to the retrieve the value

get(A)

From 'B', we can use eval

eval(B)
#[1] "A"

The OP's example is confusing. Just to understand it better,

C <- "A"
B <- as.name(C)
eval(B)
#[1] "A"

Upvotes: 2

Related Questions