Re: [R] unexpected 'else' in " else"

2022-10-28 Thread Ebert,Timothy Aaron
I appreciate this thread on coding. My preference for reading is to have complete sentences. I can read this: { if (x On Behalf Of Jorgen Harmse via R-help Sent: Friday, October 28, 2022 10:39 AM To: r-help@r-project.org Subject: Re: [R] unexpected 'else' in " else" [External Email

Re: [R] unexpected 'else' in " else"

2022-10-28 Thread Jorgen Harmse via R-help
of the code, and I would usually rather throw in a few extra delimiters than obscure the structure. Regards, Jorgen Harmse. Examples (best viewed in a real text editor so things line up): { if (x To: Jinsong Zhao Cc: "r-help@r-project.org" Subject: Re: [R] unexpected 'else' in " e

Re: [R] unexpected 'else' in " else"

2022-10-26 Thread Richard O'Keefe
. x <- y + z works fine, while x <- y + z doesn't. On Fri, 21 Oct 2022 at 22:29, Jinsong Zhao wrote: > Hi there, > > The following code would cause R error: > > > w <- 1:5 > > r <- 1:5 > > if (is.matrix(r)) > +

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

2022-10-24 Thread Bert Gunter
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

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

2022-10-24 Thread Bert Gunter
"...but 'same length and attributes (including dimensions and ‘"class"’) as ‘test’' looks wrong. The output seems to be `logical` or something related to the classes of `yes` & `no`." The documentation in fact says: "A vector of the same length and attributes (including dimensions and "class") as

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

2022-10-24 Thread Jorgen Harmse via R-help
There were several interesting points about `ifelse`. The usual behaviour seems to be that all three inputs are evaluated, and the entries of `yes` corresponding to `TRUE` in `test` are combined with the entries of `no` corresponding to `FALSE` in `test`. Moreover, `yes` & `no` seem to be

Re: [R] unexpected 'else' in " else"

2022-10-21 Thread Jeff Newmiller
gt; >Tim > >-Original Message- >From: Martin Maechler >Sent: Friday, October 21, 2022 8:43 AM >To: Ebert,Timothy Aaron >Cc: Andrew Simmons ; Jinsong Zhao ; >R-help Mailing List >Subject: Re: [R] unexpected 'else' in " else" > >[External Email]

Re: [R] unexpected 'else' in " else"

2022-10-21 Thread Ebert,Timothy Aaron
Message- From: Martin Maechler Sent: Friday, October 21, 2022 8:43 AM To: Ebert,Timothy Aaron Cc: Andrew Simmons ; Jinsong Zhao ; R-help Mailing List Subject: Re: [R] unexpected 'else' in " else" [External Email] >>>>> Ebert,Timothy Aaron >>>>> o

Re: [R] unexpected 'else' in " else"

2022-10-21 Thread Andrew Simmons
:29 Jinsong Zhao, wrote: > > > Hi there, > > > > The following code would cause R error: > > > > > w <- 1:5 > > > r <- 1:5 > > > if (is.matrix(r)) > > + r[w != 0, , drop = FALSE] > > >

Re: [R] unexpected 'else' in " else"

2022-10-21 Thread Jorgen Harmse via R-help
on is FALSE, so it might be necessary to undo an assignment, and that seems very difficult.) Regards, Jorgen Harmse. On Fri., Oct. 21, 2022, 05:29 Jinsong Zhao, wrote: > Hi there, > > The following code would cause R error: > > > w <- 1:5 > > r <- 1:5 > >

Re: [R] unexpected 'else' in " else"

2022-10-21 Thread Jinsong Zhao
Dear John, Thank you very much for the explanation. It cleared up my confusion about the syntax of "if ... else...", which in the help page of "if" said: ``` In particular, you should not have a newline between ‘}’ and ‘else’ to avoid a syntax error in entering a ‘if ... else’

Re: [R] unexpected 'else' in " else"

2022-10-21 Thread John Fox
gt; r <- 1:5      >         if (is.matrix(r))     +             r[w != 0, , drop = FALSE]      >         else r[w != 0]     Error: unexpected 'else' in "        else"     However, the code:              if (is.matrix(r))                  r[w != 0, , drop = FALSE]              else r[w !=

Re: [R] unexpected 'else' in " else"

2022-10-21 Thread Martin Maechler
the answer, but not 100% sure. > Tim > -Original Message- > From: R-help On Behalf Of Andrew Simmons > Sent: Friday, October 21, 2022 5:37 AM > To: Jinsong Zhao > Cc: R-help Mailing List > Subject: Re: [R] unexpected 'else' in " el

Re: [R] unexpected 'else' in " else"

2022-10-21 Thread Jinsong Zhao
there, The following code would cause R error:  > w <- 1:5  > r <- 1:5  >         if (is.matrix(r)) +             r[w != 0, , drop = FALSE]  >         else r[w != 0] Error: unexpected 'else' in "        else" However, the code:

Re: [R] unexpected 'else' in " else"

2022-10-21 Thread Ebert,Timothy Aaron
--- From: R-help On Behalf Of Andrew Simmons Sent: Friday, October 21, 2022 5:37 AM To: Jinsong Zhao Cc: R-help Mailing List Subject: Re: [R] unexpected 'else' in " else" [External Email] The error comes from the expression not being wrapped with braces. You could change it to if (is

Re: [R] unexpected 'else' in " else"

2022-10-21 Thread Andrew Simmons
[w != 0] On Fri., Oct. 21, 2022, 05:29 Jinsong Zhao, wrote: > Hi there, > > The following code would cause R error: > > > w <- 1:5 > > r <- 1:5 > > if (is.matrix(r)) > + r[w != 0, , drop = FALSE] > > else r[w != 0

[R] unexpected 'else' in " else"

2022-10-21 Thread Jinsong Zhao
Hi there, The following code would cause R error: > w <- 1:5 > r <- 1:5 > if (is.matrix(r)) + r[w != 0, , drop = FALSE] > else r[w != 0] Error: unexpected 'else' in "else" However, the code: if (is.matrix(r))