[R] Can anyone help why the errors are coming and rectify it?
Hi Everyone, Can anyone help why the errors are coming and rectify it? invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } else { cat(paste(invalid.ids), sep=\n) } Error: unexpected 'else' in else Error: unexpected '}' in } Thank you in advance Warm Regards Rayalu Notice: The information contained in this electronic mail message is intended only for the use of the designated recipient. This message is privileged and confidential. and the property of GVK BIO or its affiliates and subsidiaries. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone +91-40-6692tel:+91-40-6692 and destroy any and all copies of this message in your possession (whether hard copies or electronically stored copies). [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Can anyone help why the errors are coming and rectify it?
On 12-09-17 5:47 AM, Sri krishna Devarayalu Balanagu wrote: Hi Everyone, Can anyone help why the errors are coming and rectify it? invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } The lines above are two complete statements. else { The else is not allowed to start a statement. You need to make sure the if is incomplete when you start the line containing else. The usual style is if (cond) { stmt1 # The if is still incomplete, because the closing brace is missing } else { # now the else will be accepted stmt2 } Duncan Murdoch cat(paste(invalid.ids), sep=\n) } Error: unexpected 'else' in else Error: unexpected '}' in } Thank you in advance Warm Regards Rayalu Notice: The information contained in this electronic mail message is intended only for the use of the designated recipient. This message is privileged and confidential. and the property of GVK BIO or its affiliates and subsidiaries. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone +91-40-6692tel:+91-40-6692 and destroy any and all copies of this message in your possession (whether hard copies or electronically stored copies). [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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 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] Can anyone help why the errors are coming and rectify it?
On 17-Sep-2012 09:47:41 Sri krishna Devarayalu Balanagu wrote: Hi Everyone, Can anyone help why the errors are coming and rectify it? invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } else { cat(paste(invalid.ids), sep=\n) } Error: unexpected 'else' in else Error: unexpected '}' in } Thank you in advance Warm Regards Rayalu Reformatting your code (for readability) but preserving your line breaks: invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } else { cat(paste(invalid.ids), sep=\n) } } Error: unexpected 'else' in else Error: unexpected '}' in } First: The first four lines are a completed command, given the way that R parses input. After encountering the end-of-line at the fourth line, R considers that it has seen a complete command and therefore executes it. invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } Therefore the else { on the next line is not interpreted as if it were part of the preceding if() statement, since that has been considered complete and has been executed. So that else is an else with no matching if. Henc the the first error message. Second: if you count the opening { and closing }, you will see that there is one } too many, at the end, hence the second error message. The way to avoid the first error message is to put the else on the same line as the close of the if statement. Then R will recognise that it has an incomplete commend, and continue to parse further input until it has built up a complete command. So you should write: invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } else { cat(paste(invalid.ids), sep=\n) } (Note that the extra } has been omitted too). Hoping this helps, Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 17-Sep-2012 Time: 12:29:46 This message was sent by XFMail __ R-help@r-project.org mailing list 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] Can anyone help why the errors are coming and rectify it?
And now it is easy to see why we should all the one true brace style ;-) Michael On Mon, Sep 17, 2012 at 12:29 PM, Ted Harding ted.hard...@wlandres.net wrote: On 17-Sep-2012 09:47:41 Sri krishna Devarayalu Balanagu wrote: Hi Everyone, Can anyone help why the errors are coming and rectify it? invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } else { cat(paste(invalid.ids), sep=\n) } Error: unexpected 'else' in else Error: unexpected '}' in } Thank you in advance Warm Regards Rayalu Reformatting your code (for readability) but preserving your line breaks: invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } else { cat(paste(invalid.ids), sep=\n) } } Error: unexpected 'else' in else Error: unexpected '}' in } First: The first four lines are a completed command, given the way that R parses input. After encountering the end-of-line at the fourth line, R considers that it has seen a complete command and therefore executes it. invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } Therefore the else { on the next line is not interpreted as if it were part of the preceding if() statement, since that has been considered complete and has been executed. So that else is an else with no matching if. Henc the the first error message. Second: if you count the opening { and closing }, you will see that there is one } too many, at the end, hence the second error message. The way to avoid the first error message is to put the else on the same line as the close of the if statement. Then R will recognise that it has an incomplete commend, and continue to parse further input until it has built up a complete command. So you should write: invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } else { cat(paste(invalid.ids), sep=\n) } (Note that the extra } has been omitted too). Hoping this helps, Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 17-Sep-2012 Time: 12:29:46 This message was sent by XFMail __ R-help@r-project.org mailing list 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 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] Can anyone help why the errors are coming and rectify it?
Now i know why using else never worked for me - really, i'd consider this more of a bug than a feature of the language ;) On 17.09.2012, at 14:35, R. Michael Weylandt wrote: And now it is easy to see why we should all the one true brace style ;-) Michael On Mon, Sep 17, 2012 at 12:29 PM, Ted Harding ted.hard...@wlandres.net wrote: On 17-Sep-2012 09:47:41 Sri krishna Devarayalu Balanagu wrote: Hi Everyone, Can anyone help why the errors are coming and rectify it? invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } else { cat(paste(invalid.ids), sep=\n) } Error: unexpected 'else' in else Error: unexpected '}' in } Thank you in advance Warm Regards Rayalu Reformatting your code (for readability) but preserving your line breaks: invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } else { cat(paste(invalid.ids), sep=\n) } } Error: unexpected 'else' in else Error: unexpected '}' in } First: The first four lines are a completed command, given the way that R parses input. After encountering the end-of-line at the fourth line, R considers that it has seen a complete command and therefore executes it. invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } Therefore the else { on the next line is not interpreted as if it were part of the preceding if() statement, since that has been considered complete and has been executed. So that else is an else with no matching if. Henc the the first error message. Second: if you count the opening { and closing }, you will see that there is one } too many, at the end, hence the second error message. The way to avoid the first error message is to put the else on the same line as the close of the if statement. Then R will recognise that it has an incomplete commend, and continue to parse further input until it has built up a complete command. So you should write: invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } else { cat(paste(invalid.ids), sep=\n) } (Note that the extra } has been omitted too). Hoping this helps, Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 17-Sep-2012 Time: 12:29:46 This message was sent by XFMail __ R-help@r-project.org mailing list 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 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 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] Can anyone help why the errors are coming and rectify it?
On Mon, Sep 17, 2012 at 2:54 PM, Jessica Streicher j.streic...@micromata.de wrote: Now i know why using else never worked for me - really, i'd consider this more of a bug than a feature of the language ;) If it makes you feel any better (I can't imagine it would), javascript has the same 'feature' for much the same reason. Python doesn't, but then again, they don't have braces so the parsing is easier (i.e., there exist universalizable rules) Michael On 17.09.2012, at 14:35, R. Michael Weylandt wrote: And now it is easy to see why we should all the one true brace style ;-) Michael __ R-help@r-project.org mailing list 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] Can anyone help why the errors are coming and rectify it?
This is Circle 8.1.43 of 'The R Inferno'. http://www.burns-stat.com/pages/Tutor/R_inferno.pdf Pat On 17/09/2012 10:47, Sri krishna Devarayalu Balanagu wrote: Hi Everyone, Can anyone help why the errors are coming and rectify it? invalid.ids - c(1,3,5) if (length(invalid.ids)==0) { cat(No Errors found) } else { cat(paste(invalid.ids), sep=\n) } Error: unexpected 'else' in else Error: unexpected '}' in } Thank you in advance Warm Regards Rayalu Notice: The information contained in this electronic mail message is intended only for the use of the designated recipient. This message is privileged and confidential. and the property of GVK BIO or its affiliates and subsidiaries. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone +91-40-6692tel:+91-40-6692 and destroy any and all copies of this message in your possession (whether hard copies or electronically stored copies). [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ R-help@r-project.org mailing list 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.