Re: [R] is.na behavior
I don't think the question is about what an expression evaluates to, but what it is. I don't think it makes sense for an expression to be NA, but I am not a language designer. The expression NA tells the compiler that a literal NA_logical_ value is to be returned from evaluating that expression, but that is not what the expression itself is. Nor is it a no-operation... that has a different meaning than "unknown value". I would construct a function that simply returns NA and use that as the default value for the function that the OP constructed, and always call the function rather than testing what it is. On November 19, 2015 12:59:33 PM PST, Erich Neuwirth wrote: >I am not sure I undestand the issue. >But if the question is to decidedif an expression evaluates to NA, >using eval should solve the problem. >In fact, I do not really understand what an NA expression, and not an >expression evaluating to NA, >means. > > > > > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >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. -- Sent frommy phone. Please excuse my brevity. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] is.na behavior
I am not sure I undestand the issue. But if the question is to decidedif an expression evaluates to NA, using eval should solve the problem. In fact, I do not really understand what an NA expression, and not an expression evaluating to NA, means. signature.asc Description: Message signed with OpenPGP using GPGMail __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] is.na behavior
Richard, I think the reason that this gives the warning is for the rest of us who don't think about asking about missing values in non-data objects. I could imagine someone choosing a poor name for a variable and doing something like: mean <- mean(x) is.na(mean) which would then tell them whether the mean of x was missing (due to missing in x). Later in a new session they may try something similar but use a different variable name in the 1st line (e.g. Mean) but accidentally still ask for is.na(mean). So, is.na would find the mean function and report that it is not missing, but the warning would let the user know that what was checked for missingness was not what they had intended. I could also imagine meaning to write something like: is.na(mean(x)) but accidentially writing is.na(mean) instead and I would appreciate the warning that would send me back to review my code and find the mistake. On Wed, Nov 18, 2015 at 8:03 PM, Richard M. Heiberger wrote: > David, > > Your answer begs the question. > What is the problem with non-(list or vector) of type language. > To my eye both expression(abcd) and call("mean") look like they have > non-missing values, hence I anticipated that they are not NA, and therefore > that is.na() would return FALSE without a warning. > > On the html email, I turned that off years ago. It looks like gmail > (who handles > my university's email accounts) turned it back on. I just turned it off > again. > I too find it very annoying to have to revisit setting changes that I > didn't make. > Thank you for letting me know. > > Rich > > > On Wed, Nov 18, 2015 at 9:36 PM, David Winsemius > wrote: >> >>> On Nov 18, 2015, at 5:54 PM, Richard M. Heiberger wrote: >>> >>> What is the rationale for the following warning in R-3.2.2? >>> is.na(expression(abcd)) >>> [1] FALSE >>> Warning message: >>> In is.na(expression(abcd)) : >>> is.na() applied to non-(list or vector) of type ‘expression’ >> >> Well, the R interpreter does think that this is not a list: >> >>> is.list(expression(abcd)) >> [1] FALSE >> >> >>> methods(is.na) >> [1] is.na,abIndex-method is.na,denseMatrix-method >> [3] is.na,indMatrix-method is.na,nsparseMatrix-method >> [5] is.na,nsparseVector-method is.na,sparseMatrix-method >> [7] is.na,sparseVector-method is.na.coxph.penalty* >> [9] is.na.data.frame is.na.numeric_version >> [11] is.na.POSIXlt is.na.raster* >> [13] is.na.ratetable* is.na.Surv >> >> >> So the rationale is probably the same as the rationale for this warning: >> >>> is.na(call("mean", 1:4)) >> [1] FALSE FALSE >> Warning message: >> In is.na(call("mean", 1:4)) : >> is.na() applied to non-(list or vector) of type ‘language' >> >>> [[alternative HTML version deleted]] >> >> >> I’m somewhat puzzled at your use of HTML for an Rhelp posting. I thought you >> were a longtime R user? >> >> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> 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 >> Alameda, CA, USA >> > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] is.na behavior
Maybe the way to rephrase my question is to ask why there is not an is.na.expression method that does that task for me? > is.na(as.list(expression("defg"))) [1] FALSE > is.na(expression("defg")) [1] FALSE Warning message: In is.na(expression("defg")) : is.na() applied to non-(list or vector) of type 'expression' > On Wed, Nov 18, 2015 at 10:22 PM, Richard M. Heiberger wrote: > It is in context of determining if an input argument for a graph title > is missing or null or na. In any of those cases the function defines > a main title. > If the incoming title is not one of those, then I use the incoming title. > When the incoming title is an expression I see the warning. > > library(lattice) > > simple <- function(x, y, main) { > if (missing(main) || is.null(main) || is.na(main)) > main <-"abcd" > xyplot(y ~ x, main=main) > } > > simple(1, 2) > simple(1, 2, main=expression("defg")) > > ## In the real case the constructed title is not a simple character > ## string, but the result of function call with several incoming > ## arguments and several computed arguments. It is of a complexity > ## that making it the default in the calling sequence would > ## unnecessarily complicate the calling sequence. > > On Wed, Nov 18, 2015 at 10:04 PM, William Dunlap wrote: >> You can convert the expression to a list and use is.na on that: >>> e <- expression(1+NA, NA, 7, function(x)x+1) >>> is.na(as.list(e)) >>[1] FALSE TRUE FALSE FALSE >> and you can do the same for a call object >>> is.na(as.list(quote(func(arg1, tag2=NA, tag3=log(NA) >> tag2 tag3 >>FALSE FALSE TRUE FALSE >> >> However, what is your motivation for wanting to apply is.na to an expression? >> >> Bill Dunlap >> TIBCO Software >> wdunlap tibco.com >> >> >> On Wed, Nov 18, 2015 at 5:54 PM, Richard M. Heiberger >> wrote: >>> What is the rationale for the following warning in R-3.2.2? >>> is.na(expression(abcd)) >>> [1] FALSE >>> Warning message: >>> In is.na(expression(abcd)) : >>> is.na() applied to non-(list or vector) of type 'expression' >>> >>> [[alternative HTML version deleted]] >>> >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] is.na behavior
It is in context of determining if an input argument for a graph title is missing or null or na. In any of those cases the function defines a main title. If the incoming title is not one of those, then I use the incoming title. When the incoming title is an expression I see the warning. library(lattice) simple <- function(x, y, main) { if (missing(main) || is.null(main) || is.na(main)) main <-"abcd" xyplot(y ~ x, main=main) } simple(1, 2) simple(1, 2, main=expression("defg")) ## In the real case the constructed title is not a simple character ## string, but the result of function call with several incoming ## arguments and several computed arguments. It is of a complexity ## that making it the default in the calling sequence would ## unnecessarily complicate the calling sequence. On Wed, Nov 18, 2015 at 10:04 PM, William Dunlap wrote: > You can convert the expression to a list and use is.na on that: >> e <- expression(1+NA, NA, 7, function(x)x+1) >> is.na(as.list(e)) >[1] FALSE TRUE FALSE FALSE > and you can do the same for a call object >> is.na(as.list(quote(func(arg1, tag2=NA, tag3=log(NA) > tag2 tag3 >FALSE FALSE TRUE FALSE > > However, what is your motivation for wanting to apply is.na to an expression? > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > > On Wed, Nov 18, 2015 at 5:54 PM, Richard M. Heiberger wrote: >> What is the rationale for the following warning in R-3.2.2? >> >>> is.na(expression(abcd)) >> [1] FALSE >> Warning message: >> In is.na(expression(abcd)) : >> is.na() applied to non-(list or vector) of type 'expression' >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] is.na behavior
You can convert the expression to a list and use is.na on that: > e <- expression(1+NA, NA, 7, function(x)x+1) > is.na(as.list(e)) [1] FALSE TRUE FALSE FALSE and you can do the same for a call object > is.na(as.list(quote(func(arg1, tag2=NA, tag3=log(NA) tag2 tag3 FALSE FALSE TRUE FALSE However, what is your motivation for wanting to apply is.na to an expression? Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Nov 18, 2015 at 5:54 PM, Richard M. Heiberger wrote: > What is the rationale for the following warning in R-3.2.2? > >> is.na(expression(abcd)) > [1] FALSE > Warning message: > In is.na(expression(abcd)) : > is.na() applied to non-(list or vector) of type 'expression' > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] is.na behavior
David, Your answer begs the question. What is the problem with non-(list or vector) of type language. To my eye both expression(abcd) and call("mean") look like they have non-missing values, hence I anticipated that they are not NA, and therefore that is.na() would return FALSE without a warning. On the html email, I turned that off years ago. It looks like gmail (who handles my university's email accounts) turned it back on. I just turned it off again. I too find it very annoying to have to revisit setting changes that I didn't make. Thank you for letting me know. Rich On Wed, Nov 18, 2015 at 9:36 PM, David Winsemius wrote: > >> On Nov 18, 2015, at 5:54 PM, Richard M. Heiberger wrote: >> >> What is the rationale for the following warning in R-3.2.2? >> >>> is.na(expression(abcd)) >> [1] FALSE >> Warning message: >> In is.na(expression(abcd)) : >> is.na() applied to non-(list or vector) of type ‘expression’ > > Well, the R interpreter does think that this is not a list: > >> is.list(expression(abcd)) > [1] FALSE > > >> methods(is.na) > [1] is.na,abIndex-method is.na,denseMatrix-method > [3] is.na,indMatrix-method is.na,nsparseMatrix-method > [5] is.na,nsparseVector-method is.na,sparseMatrix-method > [7] is.na,sparseVector-method is.na.coxph.penalty* > [9] is.na.data.frame is.na.numeric_version > [11] is.na.POSIXlt is.na.raster* > [13] is.na.ratetable* is.na.Surv > > > So the rationale is probably the same as the rationale for this warning: > >> is.na(call("mean", 1:4)) > [1] FALSE FALSE > Warning message: > In is.na(call("mean", 1:4)) : > is.na() applied to non-(list or vector) of type ‘language' > >> [[alternative HTML version deleted]] > > > I’m somewhat puzzled at your use of HTML for an Rhelp posting. I thought you > were a longtime R user? > > __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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 > Alameda, CA, USA > __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] is.na behavior
> On Nov 18, 2015, at 5:54 PM, Richard M. Heiberger wrote: > > What is the rationale for the following warning in R-3.2.2? > >> is.na(expression(abcd)) > [1] FALSE > Warning message: > In is.na(expression(abcd)) : > is.na() applied to non-(list or vector) of type ‘expression’ Well, the R interpreter does think that this is not a list: > is.list(expression(abcd)) [1] FALSE > methods(is.na) [1] is.na,abIndex-method is.na,denseMatrix-method [3] is.na,indMatrix-method is.na,nsparseMatrix-method [5] is.na,nsparseVector-method is.na,sparseMatrix-method [7] is.na,sparseVector-method is.na.coxph.penalty* [9] is.na.data.frame is.na.numeric_version [11] is.na.POSIXlt is.na.raster* [13] is.na.ratetable* is.na.Surv So the rationale is probably the same as the rationale for this warning: > is.na(call("mean", 1:4)) [1] FALSE FALSE Warning message: In is.na(call("mean", 1:4)) : is.na() applied to non-(list or vector) of type ‘language' > [[alternative HTML version deleted]] I’m somewhat puzzled at your use of HTML for an Rhelp posting. I thought you were a longtime R user? __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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 Alameda, CA, USA __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] is.na behavior
What is the rationale for the following warning in R-3.2.2? > is.na(expression(abcd)) [1] FALSE Warning message: In is.na(expression(abcd)) : is.na() applied to non-(list or vector) of type 'expression' [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.