[R] [EXTERNAL] Re: unexpected 'else' in " else" (Ebert, Timothy Aaron)

Jorgen Harmse JH@rm@e @end|ng |rom roku@com
Tue Oct 25 17:06:27 CEST 2022


Good catch! I also misread it, and I think most people would. If I wanted to write confusing documentation then I could play similar games with 'mode' and 'length'.

Regards,
Jorgen Harmse.



> test <- c(TRUE,FALSE,FALSE)

> attr(test,'class') <- 'foo' # probably a bad idea, but I want to see what will happen

> z <- ifelse(test, 1:3, 7:9)

> attr(z,'class')

[1] "foo"

> attr(z,'mode')

NULL

> attr(z,'length')

NULL




From: Bert Gunter <bgunter.4567 using gmail.com>
Date: Monday, 24October, 2022 at 12:07
To: Jorgen Harmse <JHarmse using roku.com>
Cc: r-help using r-project.org <r-help using r-project.org>
Subject: [EXTERNAL] Re: [R] unexpected 'else' in " else" (Ebert,Timothy Aaron)
I wanted to follow up.
A more careful reading of the following:
"A vector of the same length and attributes (including dimensions and
"class") as test..."

So the above **refers only to a "class" attribute that appears among
the attributes of test and result**. Using my previous example, note
that:

 z <- c(TRUE,TRUE,FALSE)
> attributes(z)
NULL ## so no 'class' among attributes(z)
## However
> class(z)  ## S3 class
[1] "logical"
## Similarly
> w <- ifelse(z,5,'a')
> attributes(w)
NULL ## so no 'class' among attributes(w)
> class(w)   ##S3 class
[1] "character"

So my (anyway) confusion stems from conflating the S3 'class' of the
object with a "class" attribute, of which there is none.

Nevertheless, I believe that the phrase I suggested (or something
along those lines) might clarify how the S3 class is determined and
perhaps better distinguish it from a "class" attribute among the
attributes, if there there is such. Or maybe that part of the doc
should just be removed.

My guess is that this documentation has been around for a long time
and no one has gotten around to revising it once S3 classes came into
wider use. ... or saw the need to revise it, anyway.

-- Bert




	[[alternative HTML version deleted]]



More information about the R-help mailing list