Re: [R] From Strings to Variable name. When get does not work

2014-03-12 Thread Greg Snow
You can use get to grab the object, then subset it: > test <- list(a=2) > get('test')[['a']] [1] 2 This way you can even have the variable names in other variables: > whichvar <- 'a' > whichlist <- 'test' > get(whichlist)[[whichvar]] [1] 2 Even better would be to have any lists that you want to

Re: [R] From Strings to Variable name. When get does not work

2014-03-12 Thread Prof Brian Ripley
On 12/03/2014 07:42, Alaios wrote: Hi all, I would like to turn some long strings like MyString$Myfield$MySubfield into variables but it looks like that the get does not like lists Those are expressions not names, so you need to parse them. > eval(parse(text = "test$a")) [1] 2 so for exam

[R] From Strings to Variable name. When get does not work

2014-03-12 Thread Alaios
Hi all, I would like to turn some long strings like MyString$Myfield$MySubfield into variables but it looks like that the get does not like lists so for example:  test<-list(a=2) test >$a [1] 2 get("test") >$a [1] 2 get("test$a") >Fehler in get("test$a") : Objekt 'test$a' nicht ge