Hi there, Two simple questions: 1) How do I comment out several lines in R? Do I need to type # in the beginning of each line? 2) I have got a few lines of codes that draws sin, cos and tan (supposedly) below. My codes can draw sin() and cos() perfectly fine, but when it comes to tan(), the last part which I have commentted out, I have problem. It does not draw what it''s supposed to do. Thanks... Ko-Kang layout.my <- function (m, n) { par(mfrow = c(m, n)) } x <- 0:12566 / 1000 # Range from 0 to 4*pi layout.my( 1, 2 ) plot( sin(x), type = "l", xaxs = "i", yaxs = "i", axes = F, xlab = "x", ylab = "sin(x)", main = "Y = sin(x), x = [ 0, 720 ]" ) axis( 2, at = seq( -1, 1, by=1 ),las = 2 ) box(lty="dotted") abline( h = 0, lwd = 1 ) plot( cos(x), type = "l", xaxs = "i", yaxs = "i", axes = F, xlab = "x", ylab = "cos(x)", main = "Y = cos(x), x = [ 0, 720 ]" ) axis( 2, at = seq( -1, 1, by=1 ),las = 2 ) box(lty="dotted") abline( h = 0, lwd = 1 ) #plot( tan(x), type = "l", # xaxs = "i", yaxs = "i", axes = F, # xlab = "x", ylab = "tan(x)", # main = "Y = sin(x), x = [ 0, 360 ]" # ) #axis( 2, at = seq( -1, 1, by=1 ),las = 2 ) #box(lty="dotted") #abline( h = 0, lwd = 1 ) -- ----------------------------------------------------------------------------------- Ko-Kang Wang Undergraduate Student Computer Science/Statistics Double Major University of Auckland Auckland 1005 New Zealand ----------------------------------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 31 May 2000, Ko-Kang Wang wrote:> Hi there, > > Two simple questions: > > 1) How do I comment out several lines in R? Do I need to type # in the > beginning of each line?Yes> 2) I have got a few lines of codes that draws sin, cos and tan > (supposedly) below. My codes can draw sin() and cos() perfectly fine, > but when it comes to tan(), the last part which I have commentted out, I > have problem. It does not draw what it''s supposed to do.I think it draws what it''s supposed to. It doesn''t draw what you want, perhaps. The problem is that you are drawing an unbounded function, so what you get will be determined almost entirely by how close x gets to the singularities at odd multiples of pi/2. You probably want to plot something like pmax(-10,pmin(10,tan(x))) or ifelse(abs(tan(x))>10,NA,tan(x)) -thomas Thomas Lumley Assistant Professor, Biostatistics University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
One quick and dirty answer to your first question is that if the lines you want to comment out all have acceptable R syntax (as in your example) you can just put if (FALSE) {} around the stuff you want to comment out. This won''t work if you have open parentheses or other "syntax errors" in the commented region. On Wed, 31 May 2000, Ko-Kang Wang wrote:> Hi there, > > Two simple questions: > > 1) How do I comment out several lines in R? Do I need to type # in the > beginning of each line?-- Ben Bolker bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker 318 Carr Hall/Box 118525 tel: (352) 392-5697 Gainesville, FL 32611-8525 fax: (352) 392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 31 May 2000, Ko-Kang Wang wrote:>Two simple questions: > >1) How do I comment out several lines in R? Do I need to type # in the >beginning of each line?If you are using ESS (I saw you''re on Win98, but there is NTEmacs... :-)), you can mark the region and go M-x comment-region That''ll do the trick. I''m not sure how you should uncomment it again, though. Best, Kjetil -- Kjetil Kjernsmo Graduate astronomy-student Problems worthy of attack University of Oslo, Norway Prove their worth by hitting back E-mail: kjetikj at astro.uio.no - Piet Hein Homepage <URL:http://www.astro.uio.no/~kjetikj/> Webmaster at skepsis.no -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Kjetil Kjernsmo <kjetil.kjernsmo at astro.uio.no> writes:> If you are using ESS (I saw you''re on Win98, but there is NTEmacs... :-)), > you can mark the region and go > M-x comment-region > That''ll do the trick. I''m not sure how you should uncomment it again, > though.C-u M-x comment-region -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /''_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Ben Bolker <ben at zoo.ufl.edu> writes:> if (FALSE) {} > > around the stuff you want to comment out. > This won''t work if you have open parentheses or other "syntax errors" in > the commented region...and if you use it to remove largish blocks in scripts fed to stdin, you''ll notice that it takes quit a lot of time. This is due to a current silliness in the R parser: Whenever we see a newline, we check whether the expression is complete. If so, then we evaluate it, otherwise we *reparse* what has already been seen, adding another line. This makes parsing O(k^2) in the number of lines in an expression which is really unnecessary. It''s just that noone has figured out how to do the required checkpointing of the bison/yacc parser yet. The effect doesn''t happen when you source() files, because in that case we always parse the entire file before executing it. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /''_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Just out of curiousity, why is it I can''t do multiple commenting in R. I have to type # in front of each line (well, it''s true). If there are 20 or more lines it becomes a bit annoying. In SAS there is /* blah blah blah */, which comments out an entire block. Java and C++ have the similar feature too. Will it be possible to put this feature in R in the future? Just some personal opinions, Ko-Kang Peter Dalgaard BSA wrote:> Ben Bolker <ben at zoo.ufl.edu> writes: > > > if (FALSE) {} > > > > around the stuff you want to comment out. > > This won''t work if you have open parentheses or other "syntax errors" in > > the commented region. > > ..and if you use it to remove largish blocks in scripts fed to stdin, > you''ll notice that it takes quit a lot of time. This is due to a > current silliness in the R parser: Whenever we see a newline, we check > whether the expression is complete. If so, then we evaluate it, > otherwise we *reparse* what has already been seen, adding another > line. This makes parsing O(k^2) in the number of lines in an > expression which is really unnecessary. It''s just that noone has > figured out how to do the required checkpointing of the bison/yacc > parser yet. The effect doesn''t happen when you source() files, because > in that case we always parse the entire file before executing it. > > -- > O__ ---- Peter Dalgaard Blegdamsvej 3 > c/ /''_ --- Dept. of Biostatistics 2200 Cph. N > (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 > ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907-- ----------------------------------------------------------------------------------- Ko-Kang Wang Undergraduate Student Computer Science/Statistics Double Major University of Auckland Auckland 1005 New Zealand ----------------------------------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 31-May-2000 Kjetil Kjernsmo wrote:>>1) How do I comment out several lines in R? Do I need to type # in the >>beginning of each line? > > If you are using ESS (I saw you''re on Win98, but there is NTEmacs... :-)), > you can mark the region and go > M-x comment-regionThe other way is to put point at the beginning of the first line to be commented, set the mark (C-@), move point to the beginning of the last line to be commented, then C-x r t #. This works without ESS, too. ______________________________________________________________________ Stuart Luppescu -=-=- University of Chicago $(B:MJ8$HCRF`H~$NIc(B -=-=- s-luppescu at uchicago.edu http://www.consortium-chicago.org/people/sl/sl.html ICQ #21172047 AIM: psycho7070 I''ll show you MY telex number if you show me YOURS ...>> Sent on 31-May-2000 at 12:33:08 with xfmail-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._