I am introducing the scan() function to my class. Consider the following file (Scanexamp.Rnw ) \documentclass[12pt]{article} \begin{document} <<>>height = scan() 64 62 66 65 62 69 72 72 70 part = scan(what = character(0)) "Soprano" "Soprano" "Soprano" "Alto" "Alto" "Tenor" "Tenor" "Bass" "Bass" sh = data.frame(height, part) sh @ \end{document} Now what happens when I attempt to Sweave this is > Sweave("scanexamp.Rnw") Writing to file scanexamp.tex Processing code chunks ... 1 : echo term verbatim Error: chunk 1 Error in parse(text = chunk) : unexpected numeric constant in: "height = scan() 64 62" > Comments would be appreciated. (And thanks to Ross Darnell for a lot of help on another list.) Cheers, Murray Jorgensen -- Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, University of Waikato, Hamilton, New Zealand Email: maj at waikato.ac.nz Fax 7 838 4155 Phone +64 7 838 4773 wk Home +64 7 825 0441 Mobile 021 0200 8350
On Jul 26, 2010, at 11:54 PM, Murray Jorgensen wrote:> I am introducing the scan() function to my class. Consider the > following file (Scanexamp.Rnw ) > > \documentclass[12pt]{article} > > \begin{document} > <<>>> height = scan()> 64 62 66 65 62 > 69 72 72 70Have you considered adding an empty line or an ";" after the closing paren of scan? (At the console the semi-colon gambit has the desired effect while the empty line strategy fails.)> > part = scan(what = character(0)) > "Soprano" "Soprano" "Soprano" > "Alto" "Alto" "Tenor" > "Tenor" "Bass" "Bass" > > sh = data.frame(height, part) > sh > @ > \end{document} > > Now what happens when I attempt to Sweave this is > > > Sweave("scanexamp.Rnw") > Writing to file scanexamp.tex > Processing code chunks ... > 1 : echo term verbatim > > Error: chunk 1 > Error in parse(text = chunk) : unexpected numeric constant in: > "height = scan() > 64 62" > > > > Comments would be appreciated. (And thanks to Ross Darnell for a lot > of help on another list.) > > Cheers, Murray Jorgensen > > -- > Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html > Department of Statistics, University of Waikato, Hamilton, New Zealand > Email: maj at waikato.ac.nz Fax 7 838 4155 > Phone +64 7 838 4773 wk Home +64 7 825 0441 Mobile 021 0200 8350 > > ______________________________________________ > R-help at 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.David Winsemius, MD Heritage Laboratories West Hartford, CT
Both suggestions generate similar errors to those of the original code. I would also be worried if the results would not puzzle my students. But thanks! Murray David Winsemius wrote:> > On Jul 26, 2010, at 11:54 PM, Murray Jorgensen wrote: > >> I am introducing the scan() function to my class. Consider the >> following file (Scanexamp.Rnw ) >> >> \documentclass[12pt]{article} >> >> \begin{document} >> <<>>>> height = scan() > >> 64 62 66 65 62 >> 69 72 72 70 > > Have you considered adding an empty line or an ";" after the closing > paren of scan? (At the console the semi-colon gambit has the desired > effect while the empty line strategy fails.) > >> >> part = scan(what = character(0)) >> "Soprano" "Soprano" "Soprano" >> "Alto" "Alto" "Tenor" >> "Tenor" "Bass" "Bass" >> >> sh = data.frame(height, part) >> sh >> @ >> \end{document} >> >> Now what happens when I attempt to Sweave this is >> >> > Sweave("scanexamp.Rnw") >> Writing to file scanexamp.tex >> Processing code chunks ... >> 1 : echo term verbatim >> >> Error: chunk 1 >> Error in parse(text = chunk) : unexpected numeric constant in: >> "height = scan() >> 64 62" >> > >> >> Comments would be appreciated. (And thanks to Ross Darnell for a lot >> of help on another list.) >> >> Cheers, Murray Jorgensen >> >> -- >> Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html >> Department of Statistics, University of Waikato, Hamilton, New Zealand >> Email: maj at waikato.ac.nz Fax 7 838 4155 >> Phone +64 7 838 4773 wk Home +64 7 825 0441 Mobile 021 0200 8350 >> >> ______________________________________________ >> R-help at 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. > > David Winsemius, MD > Heritage Laboratories > West Hartford, CT >-- Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, University of Waikato, Hamilton, New Zealand Email: maj at waikato.ac.nz majorgensen at ihug.co.nz Fax 7 838 4155 Phone +64 7 838 4773 wk Home +64 7 825 0441 Mobile 021 0200 8350
On Jul 27, 2010, at 7:01 AM, Murray Jorgensen wrote:> Both suggestions generate similar errors to those of the original > code. I would also be worried if the results would not puzzle my > students.You are teaching them about R or about Sweave? You are setting up code that is designed to run at an open console session, but submitting it to a batch process. http://finzi.psych.upenn.edu/R/Rhelp02/archive/31347.html After reading that I am wondering if you could set up a textConnection first and then scan from that? > con <- textConnection("64 62 66 65 62\n69 72 72 70") > scan(file=con) Read 9 items [1] 64 62 66 65 62 69 72 72 70 -- David.> > But thanks! Murray > > David Winsemius wrote: >> On Jul 26, 2010, at 11:54 PM, Murray Jorgensen wrote: >>> I am introducing the scan() function to my class. Consider the >>> following file (Scanexamp.Rnw ) >>> >>> \documentclass[12pt]{article} >>> >>> \begin{document} >>> <<>>>>> height = scan() >>> 64 62 66 65 62 >>> 69 72 72 70 >> Have you considered adding an empty line or an ";" after the >> closing paren of scan? (At the console the semi-colon gambit has >> the desired effect while the empty line strategy fails.) >>> >>> part = scan(what = character(0)) >>> "Soprano" "Soprano" "Soprano" >>> "Alto" "Alto" "Tenor" >>> "Tenor" "Bass" "Bass" >>> >>> sh = data.frame(height, part) >>> sh >>> @ >>> \end{document} >>> >>> Now what happens when I attempt to Sweave this is >>> >>> > Sweave("scanexamp.Rnw") >>> Writing to file scanexamp.tex >>> Processing code chunks ... >>> 1 : echo term verbatim >>> >>> Error: chunk 1 >>> Error in parse(text = chunk) : unexpected numeric constant in: >>> "height = scan() >>> 64 62" >>> > >>> >>> Comments would be appreciated. (And thanks to Ross Darnell for a >>> lot of help on another list.) >>> >>> Cheers, Murray Jorgensen >>> >>> -- >>> Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html >>> Department of Statistics, University of Waikato, Hamilton, New >>> Zealand >>> Email: maj at waikato.ac.nz Fax 7 838 >>> 4155 >>> Phone +64 7 838 4773 wk Home +64 7 825 0441 Mobile 021 0200 >>> 8350 >>> >>> ______________________________________________ >>> R-help at 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. >> David Winsemius, MD >> Heritage Laboratories >> West Hartford, CT > > > -- > Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html > Department of Statistics, University of Waikato, Hamilton, New Zealand > Email: maj at waikato.ac.nz majorgensen at ihug.co.nz Fax 7 838 4155 > Phone +64 7 838 4773 wk Home +64 7 825 0441 Mobile 021 0200 8350David Winsemius, MD Heritage Laboratories West Hartford, CT
On Tue, 27 Jul 2010, Murray Jorgensen wrote:> I am introducing the scan() function to my class. Consider the following file > (Scanexamp.Rnw ) > > \documentclass[12pt]{article} > > \begin{document} > <<>> > height = scan() > 64 62 66 65 62 > 69 72 72 70 > > part = scan(what = character(0)) > "Soprano" "Soprano" "Soprano" > "Alto" "Alto" "Tenor" > "Tenor" "Bass" "Bass" > > sh = data.frame(height, part) > sh > @ > \end{document} > > Now what happens when I attempt to Sweave this is > >> Sweave("scanexamp.Rnw") > Writing to file scanexamp.tex > Processing code chunks ... > 1 : echo term verbatim > > Error: chunk 1 > Error in parse(text = chunk) : unexpected numeric constant in: > "height = scan() > 64 62" >>Right. Sweave is trying to parse the whole chunk. It cannot parse "64 62 66 65 62". (And the command line cannot parse it either - try typing it at the R prompt.) If you put each number on a separate line, Sweave will parse it, but when scan() runs, it will prompt for input and accept it from STDIN just as when run from the command line. Which probably isn't what you want. I'd guess the path of least resistance is to have a bit of deception. Use two chunks - one like that above but with eval=F and another with eval=T,echo=F with code like this tcon <- textConnection(" 64 62 66 65 62 69 72 72 70" ) height = scan(tcon) close(tcon) ... If the deception doesn't please you, then use a file as in example( scan ) to illustrate scan() HTH, Chuck> > Comments would be appreciated. (And thanks to Ross Darnell for a lot of help > on another list.) > > Cheers, Murray Jorgensen > > -- > Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html > Department of Statistics, University of Waikato, Hamilton, New Zealand > Email: maj at waikato.ac.nz Fax 7 838 4155 > Phone +64 7 838 4773 wk Home +64 7 825 0441 Mobile 021 0200 8350 > > ______________________________________________ > R-help at 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. > >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901