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.4...@gmail.com> Date: Monday, 24October, 2022 at 12:07 To: Jorgen Harmse <jhar...@roku.com> Cc: r-help@r-project.org <r-help@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]] ______________________________________________ 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.