Others have mentioned the readability issues (which are important), but
think about what would happen in the case where the variable lambda rule
ended up with a value like:

lambda.rule <- "a;system('SomeEvilSytemCommand')"

Or what if the element of the list desired has a space in its name.

And there is the whole efficiency issue.  Using '$' for subsetting lists is
a shortcut for a special (but common) case.  Using tools like paste, parse,
and eval to be able to use that short cut is kind of like saying that you
know a great shortcut between New York City and Boston and therefore
include that in your route going from London to Paris.


On Thu, Dec 27, 2012 at 5:04 AM, Heramb Gadgil <heramb.gadgil@gmail.com>wrote:

> Agreed.
>
> But the initial question was to get the output with paste function. That is
> the reason why I went for eval.
>
> Please let me know in case I am going the wrong way
>
> On Thu, Dec 27, 2012 at 4:34 PM, Jessica Streicher <
> j.streicher@micromata.de
> > wrote:
>
> > Well for one, if ever someone looks at your code, cvtest[[lambda.rule]]
> is
> > much easier to read and understand than
> > eval(parse(text=paste0("cvtest$",lambda.rule)))
> >
> >
> > On 27.12.2012, at 11:44, Heramb Gadgil wrote:
> >
> > > I am not sure why "Never ever!"
> > >
> > > Can you please elaborate. What are the negatives about the method
> > >
> > > Warm Regards,
> > > Heramb M. Gadgil
> > >
> > >
> > > On Thu, Dec 27, 2012 at 3:50 PM, Uwe Ligges <
> > ligges@statistik.tu-dortmund.de
> > >> wrote:
> > >
> > >>
> > >>
> > >> On 27.12.2012 08:09, Heramb Gadgil wrote:
> > >>
> > >>> eval(parse(text=paste0("**cvtest$",lambda.rule)))
> > >>>
> > >>
> > >> No, never ever!
> > >>
> > >> There is an R idiom made for it:
> > >>
> > >> cvtest[[lambda.rule]]
> > >>
> > >> Uwe Ligges
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >> I hope this works.
> > >>>
> > >>> On Wed, Dec 19, 2012 at 12:57 AM, Thomas Stewart
> > >>> <tgs.public.mail@gmail.com>**wrote:
> > >>>
> > >>> Soyeon-
> > >>>>
> > >>>> A possible solution:
> > >>>>
> > >>>> get(lambda.rule,envir=**list2env(cvtest))
> > >>>>
> > >>>>
> > >>>> On Tue, Dec 18, 2012 at 12:34 PM, Soyeon Kim <yunni0731@gmail.com>
> > >>>> wrote:
> > >>>>
> > >>>> Dear my R friends,
> > >>>>>
> > >>>>> I want to get a number from a list using paste function.
> > >>>>> In my example,
> > >>>>> lambda.rule <- "lambda.1se"
> > >>>>> cvtest is a list (result from cv.glmnet)
> > >>>>> and
> > >>>>> cvtest$lambda.1se
> > >>>>> [1] 1.308973
> > >>>>>
> > >>>>> I want to call the value using paste function.
> > >>>>> I used get function but there was an error.
> > >>>>> test <-  get(paste("cvtest$",lambda.**rule, sep=""))
> > >>>>> Error in get(paste("cvtest$", lambda.rule, sep = "")) :
> > >>>>>   object 'cvtest$lambda.1se' not found
> > >>>>>
> > >>>>> Do you guys know how to solve this issue?
> > >>>>>
> > >>>>> Thank you so much in advance and merry Christmas!
> > >>>>>
> > >>>>> Soyeon
> > >>>>>
> > >>>>> ______________________________**________________
> > >>>>> R-help@r-project.org mailing list
> > >>>>> https://stat.ethz.ch/mailman/**listinfo/r-help<
> > https://stat.ethz.ch/mailman/listinfo/r-help>
> > >>>>> PLEASE do read the posting guide
> > >>>>> http://www.R-project.org/**posting-guide.html<
> > http://www.R-project.org/posting-guide.html>
> > >>>>> and provide commented, minimal, self-contained, reproducible code.
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>         [[alternative HTML version deleted]]
> > >>>>
> > >>>> ______________________________**________________
> > >>>> R-help@r-project.org mailing list
> > >>>> https://stat.ethz.ch/mailman/**listinfo/r-help<
> > https://stat.ethz.ch/mailman/listinfo/r-help>
> > >>>> PLEASE do read the posting guide
> > >>>> http://www.R-project.org/**posting-guide.html<
> > http://www.R-project.org/posting-guide.html>
> > >>>> and provide commented, minimal, self-contained, reproducible code.
> > >>>>
> > >>>>
> > >>>        [[alternative HTML version deleted]]
> > >>>
> > >>> ______________________________**________________
> > >>> R-help@r-project.org mailing list
> > >>> https://stat.ethz.ch/mailman/**listinfo/r-help<
> > https://stat.ethz.ch/mailman/listinfo/r-help>
> > >>> PLEASE do read the posting guide http://www.R-project.org/**
> > >>> posting-guide.html <http://www.R-project.org/posting-guide.html>
> > >>> and provide commented, minimal, self-contained, reproducible code.
> > >>>
> > >>>
> > >
> > >       [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > R-help@r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538280@gmail.com

	[[alternative HTML version deleted]]


