Re: [Rd] How to build a list with missing values? What is missing, anyway?
On Fri, Oct 5, 2012 at 4:07 PM, Bert Gunter gunter.ber...@gene.com wrote: On Thu, Oct 4, 2012 at 6:31 PM, Peter Meilstrup explain some things, such as under what circumstances one would get a `...` used in incorrect context error. How could it possibly know that? -- Bert By looking at the code that throws the error. The code is in src/main/eval.c, and the error is thrown in several places when the symbol ... appears in a call being evaluated, and the value of the symbol is neither the special DOTSXP type nor NULL. That is, if you use ... in code and there isn't a ... formal argument in scope. -thomas -- Thomas Lumley Professor of Biostatistics University of Auckland __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to build a list with missing values? What is missing, anyway?
On Oct 5, 2012, at 03:31 , Peter Meilstrup wrote: On Thu, Oct 4, 2012 at 6:12 PM, Bert Gunter gunter.ber...@gene.com wrote: The R Language definition manual explains all of this. Read it. I always reread that before I post to this list. The only relevant mention of missing in the R Language Definition that I could find were in section 4.1.2 on page 25, and that section did not answer anything about missing as a special symbol (e.g. that my be put in a formal argument list.) It's not defined as an R object. We did consider doing so briefly, but the semantics would be weird, as you have experienced: An R object that can't be evaluated without triggering an error. It is something that is used by the internals, so that missing values propagate with lazy evaluation semantics. It happens to be implemented as the equivalent of as.name(), but that's not to be relied upon. It leaks out into user space because arguments can have missing defaults, and there needs to be a way to manipulate argument lists. It also slips out in substitute() with no argument, and I suppose that too is at least semi-intentional. It is not completely obvious that the two are necessarily identical. It's one of those things where you shouldn't rely on behavior outside of well-establihed idioms. If you do, and it breaks, you get to keep both pieces... I suppose we could try documenting it better, but it would be at the risk of authorizing semantics that we might want to change (e.g., it is far from clear that we should be allowing direct assignment of missings to simple symbols). (... and friends is a somewhat different kettle of fish which I don't want to go into just now.) -pd There is another mention of `...` in section 4.3.2 and it does not explain some things, such as under what circumstances one would get a `...` used in incorrect context error. Peter Thanks. Just so I have my mental model correct, I'm gathering that missing/`` is a symbol that the interpreter has a special rule for -- evaluating it raises an error, as opposed to objects that evaluate to themselves or variable names that evaluate to objects. Does the same sort of thing explain the behavior of `...`? When the interpreter comes across `...` in the arguments during evaluation of a call, it trips a special argument-interpolating behavior? -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to build a list with missing values? What is missing, anyway?
Why not just use the list constructor: theList - setNames(vector(list,3),letters[1:3]) ## The list components are empty = NULL, not NA) This also doesn't seem to be an R-devel topic. -- Bert On Wed, Oct 3, 2012 at 11:21 PM, Josh O'Brien joshmobr...@gmail.com wrote: Say I have argnames - c(a, b, c). From that I want to construct the equivalent of alist(a=, b=, c=). Here's a one liner that'll do that for you: argnames - letters[1:3] setNames(rep(list(bquote()), length(argnames)), argnames) - Josh -- View this message in context: http://r.789695.n4.nabble.com/How-to-build-a-list-with-missing-values-What-is-missing-anyway-tp4644957p4644965.html Sent from the R devel mailing list archive at Nabble.com. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to build a list with missing values? What is missing, anyway?
The R Language definition manual explains all of this. Read it. -- Bert On Thu, Oct 4, 2012 at 3:53 PM, Peter Meilstrup peter.meilst...@gmail.com wrote: On Wed, Oct 3, 2012 at 11:21 PM, Josh O'Brien joshmobr...@gmail.com wrote: Say I have argnames - c(a, b, c). From that I want to construct the equivalent of alist(a=, b=, c=). Here's a one liner that'll do that for you: argnames - letters[1:3] setNames(rep(list(bquote()), length(argnames)), argnames) Thanks. Just so I have my mental model correct, I'm gathering that missing/`` is a symbol that the interpreter has a special rule for -- evaluating it raises an error, as opposed to objects that evaluate to themselves or variable names that evaluate to objects. Does the same sort of thing explain the behavior of `...`? When the interpreter comes across `...` in the arguments during evaluation of a call, it trips a special argument-interpolating behavior? Peter __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to build a list with missing values? What is missing, anyway?
On Thu, Oct 4, 2012 at 6:31 PM, Peter Meilstrup peter.meilst...@gmail.com wrote: On Thu, Oct 4, 2012 at 6:12 PM, Bert Gunter gunter.ber...@gene.com wrote: The R Language definition manual explains all of this. Read it. I always reread that before I post to this list. The only relevant mention of missing in the R Language Definition that I could find were in section 4.1.2 on page 25, and that section Page 15, NA handling seems relevant, as does ?NA (at the command prompt in R). See also 2.5 in the Introduction to R tutorial. did not answer anything about missing as a special symbol (e.g. that my be put in a formal argument list.) There is another mention of `...` in section 4.3.2 and it does not See section 2.1.9 of the Language Definition manual and 10.4 of Intro to R. explain some things, such as under what circumstances one would get a `...` used in incorrect context error. How could it possibly know that? -- Bert Peter Thanks. Just so I have my mental model correct, I'm gathering that missing/`` is a symbol that the interpreter has a special rule for -- evaluating it raises an error, as opposed to objects that evaluate to themselves or variable names that evaluate to objects. Does the same sort of thing explain the behavior of `...`? When the interpreter comes across `...` in the arguments during evaluation of a call, it trips a special argument-interpolating behavior? Peter __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to build a list with missing values? What is missing, anyway?
Say I have argnames - c(a, b, c). From that I want to construct the equivalent of alist(a=, b=, c=). Here's a one liner that'll do that for you: argnames - letters[1:3] setNames(rep(list(bquote()), length(argnames)), argnames) - Josh -- View this message in context: http://r.789695.n4.nabble.com/How-to-build-a-list-with-missing-values-What-is-missing-anyway-tp4644957p4644965.html Sent from the R devel mailing list archive at Nabble.com. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to build a list with missing values? What is missing, anyway?
On Thu, Oct 4, 2012 at 6:12 PM, Bert Gunter gunter.ber...@gene.com wrote: The R Language definition manual explains all of this. Read it. I always reread that before I post to this list. The only relevant mention of missing in the R Language Definition that I could find were in section 4.1.2 on page 25, and that section did not answer anything about missing as a special symbol (e.g. that my be put in a formal argument list.) There is another mention of `...` in section 4.3.2 and it does not explain some things, such as under what circumstances one would get a `...` used in incorrect context error. Peter Thanks. Just so I have my mental model correct, I'm gathering that missing/`` is a symbol that the interpreter has a special rule for -- evaluating it raises an error, as opposed to objects that evaluate to themselves or variable names that evaluate to objects. Does the same sort of thing explain the behavior of `...`? When the interpreter comes across `...` in the arguments during evaluation of a call, it trips a special argument-interpolating behavior? Peter __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to build a list with missing values? What is missing, anyway?
On Wed, Oct 3, 2012 at 9:37 PM, Peter Meilstrup peter.meilst...@gmail.com wrote: This is tangentially related to Hadley's question. Suppose I'm building a function programmatically; I have assembled an expression for the body and I know the names of the arguments it wants to take. Suppose I have some convenience function such that writing make_function(alist(a=, b=), quote(a+b), environment()) is equivalent to writing function(a,b) a+b So how do I make the list that goes in the first argument? Suppose I start with a character vector of argument names. What I need is a list with names and quoted values, but the values are empty. Say I have argnames - c(a, b, c). From that I want to construct the equivalent of alist(a=, b=, c=). Here's one approach: args - alist() for (n in argnames) { args[[n]] - bquote() } You have to be really careful dealing with the missing symbol, because if R attempts to evaluate it, you get the missing argument error. Hadley -- RStudio / Rice University http://had.co.nz/ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel