RTFM time: what do you think the description of 'file' in ?scan says about devices (I can see nothing that says they are supported). It does however say that

          As from R 2.10.0 this can be a compressed file (see ‘file’).

which is a clear indication of what changed in R 2.10.0. Did you follow the xref?: it tells you how to use a file() connection to achieve the former behaviour.

If you are reading repeatedly from a file or device, you would do better to open a connection, read repeatedly from that connection and close it when done. So (untested, of course), something like

con <- file("COM1", "rb")
for(i in 1:10) foo <- readLines(con, n=1)
close(con)

[Technical aside: a text-mode file() connection when opened looks at the file twice, once in binary mode to read the header to see if it is compressed and if so how, then using the appropriate decompressor to prepare to read the contents.]

There are many other aspects of file() connections that will not work with devices (seeking, for example) and we decided long ago not to support them. Nevertheless, it is helpful for documentation purposes to have such reports when alpha/beta testing is requested and not three months later.

On Tue, 29 Dec 2009, Tom Gottfried wrote:

Dear list,

I have a balance connected to the serial port of a windows machine ("COM1") and I read the text output of the balance with

scan("COM1", what="character", sep="\n", n=1)

after calling the previous line I press the print key on the balance which triggers sending one line of text to the serial connection and with R 2.9.2 I get something like

Read 1 item
"+  32.004 mg"

Now with R 2.10.1 (and previously with 2.10.0) I have to press the print key on the balance twice to get the same result, thus apparently I have to send two lines of text to make scan() reading only one. But this is only when reading from the serial port, not when reading from a text file on disk. The same is true for 2.10.1 on Linux (I did not try 2.9.2 nor 2.10.0 on Linux). I can't figure out from the documentation nor the NEWS whether something should be specified differently when calling scan since 2.10.0. Any ideas what this behaviour comes from?

Here the sessionInfo() for the three cases I have tested:
R version 2.9.2 (2009-08-24)
i386-pc-mingw32

locale:
LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets
[6] methods   base

respectively:

R version 2.10.1 (2009-12-14)
i386-pc-mingw32

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

respectively:
R version 2.10.1 (2009-12-14)
x86_64-unknown-linux-gnu

locale:
[1] LC_CTYPE=de_DE.UTF-8       LC_NUMERIC=C
[3] LC_TIME=de_DE.UTF-8        LC_COLLATE=de_DE.UTF-8
[5] LC_MONETARY=C              LC_MESSAGES=de_DE.UTF-8
[7] LC_PAPER=de_DE.UTF-8       LC_NAME=C
[9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     methods   base

other attached packages:
[1] lattice_0.17-26 RODBC_1.3-1

loaded via a namespace (and not attached):
[1] grid_2.10.1

Thanks a lot!
Tom

______________________________________________
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.


--
Brian D. Ripley,                  rip...@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
______________________________________________
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.

Reply via email to