R-devel, When I run the following code on the attached file, tmp <- scan("C:/temp.csv", what=list("character","numeric"), sep=",") Then tmp[[2]] is a character vector. My impression from the help file is that it should be a numeric as specified by 'what'> sessionInfo()R version 2.5.0 (2007-04-23) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods" "base" other attached packages: lattice gdata "0.15-5" "2.3.1" My apologies if this is due to my misunderstanding. Ben
The what argument looks at what the elements are, not the word they say. Try this:> tmp <- scan("C:/temp.csv", > what=list("",0), > sep=",")Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-devel-bounces at r-project.org > [mailto:r-devel-bounces at r-project.org] On Behalf Of Benjamin Tyner > Sent: Tuesday, June 26, 2007 9:59 AM > To: r-devel at r-project.org > Subject: [Rd] possible bug in 'scan' > > R-devel, > > When I run the following code on the attached file, > > tmp <- scan("C:/temp.csv", > what=list("character","numeric"), > sep=",") > > Then tmp[[2]] is a character vector. My impression from the > help file is that it should be a numeric as specified by 'what' > > > sessionInfo() > R version 2.5.0 (2007-04-23) > i386-pc-mingw32 > > locale: > LC_COLLATE=English_United States.1252;LC_CTYPE=English_United > States.1252;LC_MONETARY=English_United > States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 > > attached base packages: > [1] "stats" "graphics" "grDevices" "utils" "datasets" > "methods" "base" > > other attached packages: > lattice gdata > "0.15-5" "2.3.1" > > My apologies if this is due to my misunderstanding. > Ben >
Hi Ben, On Tue, Jun 26, 2007 at 11:58:35AM -0400, Benjamin Tyner wrote:> R-devel, > > When I run the following code on the attached file, > > tmp <- scan("C:/temp.csv", > what=list("character","numeric"), > sep=",") > > Then tmp[[2]] is a character vector. My impression from the help file > is that it should be a numeric as specified by 'what'?scan says [...] what: the type of 'what' gives the type of data to be read. [...] so for example what=list(character(), numeric()) would presumably have worked, but not your code, as both of your list elements are of type character. Dan> > >sessionInfo() > R version 2.5.0 (2007-04-23) > i386-pc-mingw32 > > locale: > LC_COLLATE=English_United States.1252;LC_CTYPE=English_United > States.1252;LC_MONETARY=English_United > States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 > > attached base packages: > [1] "stats" "graphics" "grDevices" "utils" "datasets" > "methods" "base" > > other attached packages: > lattice gdata > "0.15-5" "2.3.1" > > My apologies if this is due to my misunderstanding. > Ben> ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
On Tue, 26 Jun 2007, Benjamin Tyner wrote:> R-devel, > > When I run the following code on the attached file, > > tmp <- scan("C:/temp.csv", > what=list("character","numeric"), > sep=",") > > Then tmp[[2]] is a character vector. My impression from the help file > is that it should be a numeric as specified by 'what'No, as "numeric" is a character vector. what: the type of 'what' gives the type of data to be read. The supported types are 'logical', 'integer', 'numeric', 'complex', 'character', 'raw' and 'list'. If 'what' is a list, it is assumed that the lines of the data file are records each containing 'length(what)' items ("fields") and the list components should have elements which are one of the first six types listed or 'NULL', see section 'Details' below. so you need what = list("", 0), say. There are even examples in 'An Introduction to R'.> >> sessionInfo() > R version 2.5.0 (2007-04-23) > i386-pc-mingw32 > > locale: > LC_COLLATE=English_United States.1252;LC_CTYPE=English_United > States.1252;LC_MONETARY=English_United > States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 > > attached base packages: > [1] "stats" "graphics" "grDevices" "utils" "datasets" > "methods" "base" > > other attached packages: > lattice gdata > "0.15-5" "2.3.1" > > My apologies if this is due to my misunderstanding. > Ben >-- 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