I want to paste in the following numbers into a scan: 0.023 0.032 0.054 0.069 0.081 0.094 0.105 0.127 0.148 0.169 0.188 0.216 they are separated by tabs alone, unless my mailer has done something to the tabs. Now have a look at this: > scan() 1: 0.0230.0320.0540.0690.0810.094 1: 0.1050.1270.1480.1690.1880.216 Error in scan() : "scan" expected a real, got "0.0230.0320.0540.0690.0810.094" > scan(sep="\t") 1: 0.0230.0320.0540.0690.0810.094 1: 0.1050.1270.1480.1690.1880.216 Error in scan(sep = " ") : "scan" expected a real, got "0.0230.0320.0540.0690.0810.094" > Platform: Windows XP Release 1.8.1 I can't seem to scan in tab-separated numbers even when I try to tell R to expect that. (this may be related to the Sweave problem I mentioned a few days ago.) Murray -- 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 +64 7 849 6486 home Mobile 021 1395 862
Murray Jorgensen wrote:> I want to paste in the following numbers into a scan: > > 0.023 0.032 0.054 0.069 0.081 0.094 > 0.105 0.127 0.148 0.169 0.188 0.216 > > they are separated by tabs alone, unless my mailer has done something to > the tabs. > > Now have a look at this: > > > scan() > 1: 0.0230.0320.0540.0690.0810.094 > 1: 0.1050.1270.1480.1690.1880.216 > Error in scan() : "scan" expected a real, got > "0.0230.0320.0540.0690.0810.094" > > scan(sep="\t") > 1: 0.0230.0320.0540.0690.0810.094 > 1: 0.1050.1270.1480.1690.1880.216 > Error in scan(sep = " ") : "scan" expected a real, got > "0.0230.0320.0540.0690.0810.094" > > > > Platform: Windows XP Release 1.8.1 > > I can't seem to scan in tab-separated numbers even when I try to tell R > to expect that. (this may be related to the Sweave problem I mentioned a > few days ago.) > > Murray >If you save the numbers to a file (say "x.txt") then scan("x.txt", sep = "\t") should do it. Or highlight your text, copy to the clipboard ("Ctrl-C"), and try: scan("clipboard", sep = "\t") Read the help for ?scan. -sundar
The problem would seem to be that the Windows GUI does not accept the TAB key as input. There is no whitespace between your values to be recongnized. Take your sequesnce and save it as a tab separated file in Excel or through Notepad, and you will be able to scan it in just fine using scan("savedfile.txt") I am not sure whether this behavior of the TAB key in the interface is intentional or not, but it is the same on my Windows 2000 machine, yet the TAB separated file reads in fine with scan(). Rob ----- Original Message ----- From: "Murray Jorgensen" <maj at stats.waikato.ac.nz> To: "R-help" <r-help at stat.math.ethz.ch> Sent: Monday, March 01, 2004 3:23 PM Subject: [R] Scanning tab-separated numbers> I want to paste in the following numbers into a scan: > > 0.023 0.032 0.054 0.069 0.081 0.094 > 0.105 0.127 0.148 0.169 0.188 0.216 > > they are separated by tabs alone, unless my mailer has done something to > the tabs. > > Now have a look at this: > > > scan() > 1: 0.0230.0320.0540.0690.0810.094 > 1: 0.1050.1270.1480.1690.1880.216 > Error in scan() : "scan" expected a real, got > "0.0230.0320.0540.0690.0810.094" > > scan(sep="\t") > 1: 0.0230.0320.0540.0690.0810.094 > 1: 0.1050.1270.1480.1690.1880.216 > Error in scan(sep = " ") : "scan" expected a real, got > "0.0230.0320.0540.0690.0810.094" > > > > Platform: Windows XP Release 1.8.1 > > I can't seem to scan in tab-separated numbers even when I try to tell R > to expect that. (this may be related to the Sweave problem I mentioned a > few days ago.) > > Murray > > -- > 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 +64 7 849 6486 home Mobile 021 1395 862 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide!http://www.R-project.org/posting-guide.html>
On Mon, 1 Mar 2004, Robert W. Baer, Ph.D. wrote:> The problem would seem to be that the Windows GUI does not accept the TAB > key as input. There is no whitespace between your values to be recongnized. > Take your sequesnce and save it as a tab separated file in Excel or through > Notepad, and you will be able to scan it in just fine using > scan("savedfile.txt") > > I am not sure whether this behavior of the TAB key in the interface is > intentional or not, but it is the same on my Windows 2000 machine, yet the > TAB separated file reads in fine with scan().It does seem to be intentional: all ctrl characters (those <= 0x1f) are reserved for controlling the console. There is no implementation of tabs in RGui, so TAB = ^I is currently ignored (along with ^G ^Q ^R ^S). Note that pasting tabs into the Unix R console does not work either (tab is used for completion in readline), and generally you should not expect to be able to paste any control characters into a console (even inside quotes). -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595