This may be a newbie question - although I did search for this error message in the archives and via google and didn't see this error: The help page for "scan" indicates that among the types of data capable of being read are:> "The supported types are 'logical', 'integer', 'numeric', 'complex', 'character', 'raw' and 'list': > 'list' values should have elements which are one of the first six types listed or 'NULL'.I have tried to use a list within a "what" list : f <- scan(file="c:/test/testout.csv",what=list(hi=0.0,bye="",wave=list(1:1000)),sep=",",skip=1) and the following error is returned: "c:/test/testout.csv", what = list(hi = 0, bye = "", : unimplemented type 'list' in 'extractItem' So, is my syntax confusing R, or is the documentation wrong, or is it some other, third, option? Thanks M -- Michael Lefsky College of Natural Resources Colorado State University --------------------------------------------------------------------- Out of the crooked timber of humanity, no straight thing was ever made- Immanuel Kant
Hi Michael An example of your list would have helped. Anyhow, why do you want to read a list? If you created a list object in R and want to save it and then read it back in other session or in some other time a good option is to write an ASCII representation of the object using dput and then recreate it using dget i.e. mylist= list(x=cars[,1], y=cars[,2]) dput(mylist,"mylist") mylistback=dget("mylist") $x [1] 4 4 7 7 8 9 10 10 10 11 11 12 12 12 12 13 13 13 13 14 14 14 14 15 15 [26] 15 16 16 17 17 17 18 18 18 18 19 19 19 20 20 20 20 20 22 23 24 24 24 24 25 $y [1] 2 10 4 22 16 10 18 26 34 17 28 14 20 24 28 26 34 34 46 [20] 26 36 60 80 20 26 54 32 40 32 40 50 42 56 76 84 36 46 68 [39] 32 48 52 56 64 66 54 70 92 93 120 85 If you want to read some other type of data take a look at the higher lever functions listed under ?read.table and the functions at library(help="foreign") I hope this helps Francisco PS: Nasty weather in Fort Collins today!>From: Michael Lefsky <lefsky at gmail.com> >Reply-To: lefsky at gmail.com >To: r-help at stat.math.ethz.ch >Subject: [R] Scan and Lists >Date: Wed, 14 Sep 2005 15:06:17 -0600 > >This may be a newbie question - although I did search for this error >message in the archives and via google and didn't see this error: > >The help page for "scan" indicates that among the types of data >capable of being read are: > > > "The supported types are 'logical', 'integer', 'numeric', 'complex', >'character', 'raw' and 'list': > > 'list' values should have elements which are one of the first six types >listed or 'NULL'. > >I have tried to use a list within a "what" list : > >f <- >scan(file="c:/test/testout.csv",what=list(hi=0.0,bye="",wave=list(1:1000)),sep=",",skip=1) > >and the following error is returned: > > "c:/test/testout.csv", what = list(hi = 0, bye = "", : > unimplemented type 'list' in 'extractItem' > >So, is my syntax confusing R, or is the documentation wrong, or is it >some other, third, option? > >Thanks > >M >-- >Michael Lefsky >College of Natural Resources >Colorado State University >--------------------------------------------------------------------- >Out of the crooked timber of humanity, >no straight thing was ever made- Immanuel Kant > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! >http://www.R-project.org/posting-guide.html
>>>>> "Michael" == Michael Lefsky <lefsky at gmail.com> >>>>> on Wed, 14 Sep 2005 15:06:17 -0600 writes:Michael> This may be a newbie question - although I did Michael> search for this error message in the archives and Michael> via google and didn't see this error: I know how useful google can be - - still, sometimes one would better spend the time differently ... You know the old IBM motto? If not, google for "IBM motto" ;-) Michael> The help page for "scan" indicates that among the types of data Michael> capable of being read are: >> "The supported types are 'logical', 'integer', 'numeric', >> 'complex', 'character', 'raw' and 'list': 'list' values >> should have elements which are one of the first six types >> listed or 'NULL'. Michael> I have tried to use a list within a "what" list : which was wrong: Michael> f <- scan(file="c:/test/testout.csv", Michael> what=list(hi=0.0,bye="",wave=list(1:1000)), Michael> sep=",",skip=1) Michael> and the following error is returned: Michael> "c:/test/testout.csv", what = list(hi = 0, bye = "", : Michael> unimplemented type 'list' in 'extractItem' Michael> So, is my syntax confusing R, or is the documentation wrong, or is it Michael> some other, third, option? 3rd: You didn't read the documentation carefully enough (though I agree that the current wording leaves a non-small possibility for confusion): In your above citation from the help page, you've left off crucial context. Here is a bit more >> what: the type of 'what' gives the type of data to be read. If >> 'what' is a list, it is assumed that the lines of the data >> file are records each containing 'length(what)' items >> ("fields"). The supported types are 'logical', 'integer', >> 'numeric', 'complex', 'character', 'raw' and 'list': 'list' >> values should have elements which are one of the first six >> types listed or 'NULL'. So 'what' has a *type* and that type can be logical, ...., and list. where list should have elements from the first six types --- which do *NOT* include list. In short: It does exclude using a *list* inside the list. Is your data <double> <character> <int> <int> .... <int> with 1000 integers, i.e. you have 1002 columns? If yes, you'd probably get what you want by whatCols <- c(list(hi=0.0, bye=""), as.list(1:1000)) f <- scan(file = "c:/test/testout.csv", what = whatCols, sep= ",", skip=1) {The point here is that c(l1, l2) is used to concatenate two lists l1 and l2; and yes: Please do use spaces {and indentation} to make your more readable ! } Michael> Thanks You're welcome, Martin Maechler, ETH Zurich