[R] using "list=" to force evaluation before execution
R. Michael Weylandt
michael.weylandt at gmail.com
Thu Jan 12 20:23:39 CET 2012
You are of course correct: I was trying to walk the line between using
"list" in the colloquial sense of "a set of things" that seems to have
motivated the formals of rm() and "list" in the sense of a VECSXP. In
retrospect, I probably shouldn't have relegated that important
distinction to a ill-phrased footnote. I think the documentation
probably explains it best:
Use the ‘list’ argument to specify objects _via_ a character vector.
Anyway, perhaps there's a silver lining to the odd argument name: it's
hard to accidentally delete all one's data.
Best,
Michael
On Thu, Jan 12, 2012 at 1:38 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>
> On Jan 12, 2012, at 12:04 PM, R. Michael Weylandt wrote:
>
>> Nope - you misunderstand entirely. Both of those functions have an
>> argument named "list" and the code you quote is just the standard way of
>> using a named argument. It could just as well read
>>
>> rm(salmon = ls())
>>
>> but that would be absurd. The list argument gets its name from the fact it
>> (usually) takes a list**, no more no less.
>
>
> Actually that is not correct. The "list" argument takes a character vector
> as input.
>
> Giving it a list with either quoted or unquoted elements creates an error:
>
>> rm(list=list("x", "x1"))
> Error in rm(list = list("x", "x1")) : invalid first argument
>> rm(list=list(x, x1))
> Error in rm(list = list(x, x1)) : invalid first argument
>
> I entirely agree with the OP that it is unnecessarily confusing, but is
> probably cast in stone because of history.
>
> --
> David.
>
>
>
>>
>> Michael
>>
>> **Not strictly true here as ls() doesn't return a list, but just go with
>> it. It's a vector of names, not a list in the data structure sense.
>>
>> On Jan 12, 2012, at 11:55 AM, Aditya Bhagwat <bhagwataditya at gmail.com>
>> wrote:
>>
>>> Dear all,
>>>
>>> I have noticed that the expression 'list =' is sometimes used to tell R
>>> to
>>> evaluate something before executing it.
>>>
>>> Two examples:
>>>
>>> rm(list=ls())
>>>
>>> a = 3
>>> myVarName = 'a'
>>> save(list=myVarName, file=...)
>>>
>>>
>>> I was wondering whether there is any documentation on this way of using
>>> "list". Which is a clearly different use than what ?list talks about, as
>>> the latter addresses the use of 'list' as a datastructure.
>>>
>>> Thanks for your help,
>>>
>>> Adi
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at 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.
>>
>>
>> ______________________________________________
>> R-help at 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.
>
>
> David Winsemius, MD
> West Hartford, CT
>
More information about the R-help
mailing list