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]]
> On Nov 18, 2015, at 5:54 PM, Richard M. Heiberger <rmh at temple.edu> 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 at 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
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 <dwinsemius at comcast.net> wrote:> >> On Nov 18, 2015, at 5:54 PM, Richard M. Heiberger <rmh at temple.edu> 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 at 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 >
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 <rmh at temple.edu> 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 at 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.
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 <wdunlap at tibco.com> 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 <rmh at temple.edu> 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 at 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.