Scan not respecting what
2
0
Entering edit mode
Gaston Fiore ▴ 40
@gaston-fiore-4224
Last seen 10.2 years ago
Hello everyone, By some (strange to me) reason, scan isn't respecting the what argument: > temp <- scan(file = "~/data/WT/NS20WTR1ChrReadsF.txt", what = 'integer', sep = ",", quote = 'NULL', comment.char = "") Read 26042606 items > class(temp) [1] "character" > typeof(temp) [1] "character" I'm new to R, and I apologize if the mistake is obvious, but could someone explain to me why this is the case? Thanks a lot, -Gaston
• 860 views
ADD COMMENT
0
Entering edit mode
@martin-morgan-1513
Last seen 4 months ago
United States
On 8/25/2010 9:21 PM, Gaston Fiore wrote: > Hello everyone, > > By some (strange to me) reason, scan isn't respecting the what argument: > >> temp<- scan(file = "~/data/WT/NS20WTR1ChrReadsF.txt", what = 'integer', sep = ",", quote = 'NULL', comment.char = "") > Read 26042606 items >> class(temp) > [1] "character" >> typeof(temp) > [1] "character" > > I'm new to R, and I apologize if the mistake is obvious, but could someone explain to me why this is the case? Hi Gaston -- The 'what' argument is an instance of the data type to be parsed, so what=integer() or what=1. Hope that helps. Martin > Thanks a lot, > > -Gaston > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD COMMENT
0
Entering edit mode
On 8/25/2010 9:57 PM, Martin Morgan wrote: > On 8/25/2010 9:21 PM, Gaston Fiore wrote: >> Hello everyone, >> >> By some (strange to me) reason, scan isn't respecting the what argument: >> >>> temp<- scan(file = "~/data/WT/NS20WTR1ChrReadsF.txt", what = >>> 'integer', sep = ",", quote = 'NULL', comment.char = "") >> Read 26042606 items >>> class(temp) >> [1] "character" >>> typeof(temp) >> [1] "character" >> >> I'm new to R, and I apologize if the mistake is obvious, but could >> someone explain to me why this is the case? > Hi Gaston -- > > The 'what' argument is an instance of the data type to be parsed, so > what=integer() or what=1. That last should be what=1L; the 'L' is R's way of saying that the whole number should be an integer rather than a numeric. Martin > > Hope that helps. > > Martin >> Thanks a lot, >> >> -Gaston >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD REPLY
0
Entering edit mode
Thanks Martin, now it gives integers. Why isn't this in the described in the R Documentation, however? From there: 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. I don't see anywhere that I should specify 1L as opposed to 'integer', even though that seems to be the correct way of achieving what I wanted since it works. Any comments? Thanks, -Gaston On Aug 26, 2010, at 1:00 AM, Martin Morgan wrote: > On 8/25/2010 9:57 PM, Martin Morgan wrote: >> On 8/25/2010 9:21 PM, Gaston Fiore wrote: >>> Hello everyone, >>> >>> By some (strange to me) reason, scan isn't respecting the what argument: >>> >>>> temp<- scan(file = "~/data/WT/NS20WTR1ChrReadsF.txt", what = 'integer', sep = ",", quote = 'NULL', comment.char = "") >>> Read 26042606 items >>>> class(temp) >>> [1] "character" >>>> typeof(temp) >>> [1] "character" >>> >>> I'm new to R, and I apologize if the mistake is obvious, but could someone explain to me why this is the case? >> Hi Gaston -- >> >> The 'what' argument is an instance of the data type to be parsed, so what=integer() or what=1. > > That last should be what=1L; the 'L' is R's way of saying that the whole number should be an integer rather than a numeric. Martin >> >> Hope that helps. >> >> Martin >>> Thanks a lot, >>> >>> -Gaston >>> >>> _______________________________________________ >>> Bioconductor mailing list >>> Bioconductor at stat.math.ethz.ch >>> https://stat.ethz.ch/mailman/listinfo/bioconductor >>> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD REPLY
0
Entering edit mode
On 8/26/2010 10:10 AM, Gaston Fiore wrote: > Thanks Martin, now it gives integers. Why isn't this in the described in the R Documentation, however? From there: > > 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. > > I don't see anywhere that I should specify 1L as opposed to 'integer', even though that seems to be the correct way of achieving what I wanted since it works. Any comments? In the usage section it shows Usage: scan(file = "", what = double(0), nmax = -1, n = -1, sep = "", and in the Details we have The type of 'what' or its components can be one of the six atomic vector types or 'NULL' (see 'is.atomic'). where 'type of' suggests > typeof(integer()) [1] "integer" > typeof("integer") [1] "character" but these are definitely obscure, and inconsistent with, e.g., read.table, where colClasses is a character vector naming the types of the columns. Martin > Thanks, > > -Gaston > > > On Aug 26, 2010, at 1:00 AM, Martin Morgan wrote: > >> On 8/25/2010 9:57 PM, Martin Morgan wrote: >>> On 8/25/2010 9:21 PM, Gaston Fiore wrote: >>>> Hello everyone, >>>> >>>> By some (strange to me) reason, scan isn't respecting the what argument: >>>> >>>>> temp<- scan(file = "~/data/WT/NS20WTR1ChrReadsF.txt", what = 'integer', sep = ",", quote = 'NULL', comment.char = "") >>>> Read 26042606 items >>>>> class(temp) >>>> [1] "character" >>>>> typeof(temp) >>>> [1] "character" >>>> >>>> I'm new to R, and I apologize if the mistake is obvious, but could someone explain to me why this is the case? >>> Hi Gaston -- >>> >>> The 'what' argument is an instance of the data type to be parsed, so what=integer() or what=1. >> That last should be what=1L; the 'L' is R's way of saying that the whole number should be an integer rather than a numeric. Martin >>> Hope that helps. >>> >>> Martin >>>> Thanks a lot, >>>> >>>> -Gaston >>>> >>>> _______________________________________________ >>>> Bioconductor mailing list >>>> Bioconductor at stat.math.ethz.ch >>>> https://stat.ethz.ch/mailman/listinfo/bioconductor >>>> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >>> _______________________________________________ >>> Bioconductor mailing list >>> Bioconductor at stat.math.ethz.ch >>> https://stat.ethz.ch/mailman/listinfo/bioconductor >>> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD REPLY
0
Entering edit mode
Hi Gaston, On 8/26/2010 1:10 PM, Gaston Fiore wrote: > Thanks Martin, now it gives integers. Why isn't this in the described > in the R Documentation, however? From there: > > 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. > > I don't see anywhere that I should specify 1L as opposed to > 'integer', even though that seems to be the correct way of achieving > what I wanted since it works. Any comments? As with much documentation (not just R!), the actual meaning of the words used is clear a posteriori, but maybe not a priori. Look at the description of 'what' again. It says "the *type* of 'what' gives the type of data to be read". Now is the type of "integer" integer, or is it character? Any of 'logical', 'integer', 'numeric', 'complex', etc are all character strings that describe something else. But the help doesn't say that you should give something that describes what you are scan()ning, but something that is of the *type* of what you are scan()ning. So on first read, it is pretty confusing (I was confused too), but if you look carefully at what is written, it is clear. But if you really object to the wording, you can always submit patches to the documentation on the R-devel list, which is how Open Source projects get improved. Best, Jim > > Thanks, > > -Gaston > > > On Aug 26, 2010, at 1:00 AM, Martin Morgan wrote: > >> On 8/25/2010 9:57 PM, Martin Morgan wrote: >>> On 8/25/2010 9:21 PM, Gaston Fiore wrote: >>>> Hello everyone, >>>> >>>> By some (strange to me) reason, scan isn't respecting the what >>>> argument: >>>> >>>>> temp<- scan(file = "~/data/WT/NS20WTR1ChrReadsF.txt", what = >>>>> 'integer', sep = ",", quote = 'NULL', comment.char = "") >>>> Read 26042606 items >>>>> class(temp) >>>> [1] "character" >>>>> typeof(temp) >>>> [1] "character" >>>> >>>> I'm new to R, and I apologize if the mistake is obvious, but >>>> could someone explain to me why this is the case? >>> Hi Gaston -- >>> >>> The 'what' argument is an instance of the data type to be parsed, >>> so what=integer() or what=1. >> >> That last should be what=1L; the 'L' is R's way of saying that the >> whole number should be an integer rather than a numeric. Martin >>> >>> Hope that helps. >>> >>> Martin >>>> Thanks a lot, >>>> >>>> -Gaston >>>> >>>> _______________________________________________ Bioconductor >>>> mailing list Bioconductor at stat.math.ethz.ch >>>> https://stat.ethz.ch/mailman/listinfo/bioconductor Search the >>>> archives: >>>> http://news.gmane.org/gmane.science.biology.informatics.conductor >>> >>> >>>> _______________________________________________ >>> Bioconductor mailing list Bioconductor at stat.math.ethz.ch >>> https://stat.ethz.ch/mailman/listinfo/bioconductor Search the >>> archives: >>> http://news.gmane.org/gmane.science.biology.informatics.conductor >> > >>> > _______________________________________________ Bioconductor mailing > list Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor Search the > archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor -- James W. MacDonald, M.S. Biostatistician Douglas Lab University of Michigan Department of Human Genetics 5912 Buhl 1241 E. Catherine St. Ann Arbor MI 48109-5618 734-615-7826 ********************************************************** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues
ADD REPLY
0
Entering edit mode
To beat on this character(0) is a zero-length character vector, so the type is the same as "macdonald", which means what = list(character(0)) is the same as what = list("macdonald") Now, 1L is 1 as an integer, so 1L is the same as as.integer(1) and the same as integer(0) Kasper On Thu, Aug 26, 2010 at 1:21 PM, James W. MacDonald <jmacdon at="" med.umich.edu=""> wrote: > Hi Gaston, > > On 8/26/2010 1:10 PM, Gaston Fiore wrote: >> >> Thanks Martin, now it gives integers. Why isn't this in the described >> in the R Documentation, however? From there: >> >> 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. >> >> I don't see anywhere that I should specify 1L as opposed to >> 'integer', even though that seems to be the correct way of achieving >> what I wanted since it works. Any comments? > > As with much documentation (not just R!), the actual meaning of the words > used is clear a posteriori, but maybe not a priori. > > Look at the description of 'what' again. It says "the *type* of 'what' gives > the type of data to be read". > > Now is the type of "integer" integer, or is it character? Any of 'logical', > 'integer', 'numeric', 'complex', etc are all character strings that describe > something else. > > But the help doesn't say that you should give something that describes what > you are scan()ning, but something that is of the *type* of what you are > scan()ning. > > So on first read, it is pretty confusing (I was confused too), but if you > look carefully at what is written, it is clear. > > But if you really object to the wording, you can always submit patches to > the documentation on the R-devel list, which is how Open Source projects get > improved. > > Best, > > Jim > > >> >> Thanks, >> >> -Gaston >> >> >> On Aug 26, 2010, at 1:00 AM, Martin Morgan wrote: >> >>> On 8/25/2010 9:57 PM, Martin Morgan wrote: >>>> >>>> On 8/25/2010 9:21 PM, Gaston Fiore wrote: >>>>> >>>>> Hello everyone, >>>>> >>>>> By some (strange to me) reason, scan isn't respecting the what >>>>> argument: >>>>> >>>>>> temp<- scan(file = "~/data/WT/NS20WTR1ChrReadsF.txt", what = >>>>>> 'integer', sep = ",", quote = 'NULL', comment.char = "") >>>>> >>>>> Read 26042606 items >>>>>> >>>>>> class(temp) >>>>> >>>>> [1] "character" >>>>>> >>>>>> typeof(temp) >>>>> >>>>> [1] "character" >>>>> >>>>> I'm new to R, and I apologize if the mistake is obvious, but >>>>> could someone explain to me why this is the case? >>>> >>>> Hi Gaston -- >>>> >>>> The 'what' argument is an instance of the data type to be parsed, >>>> so what=integer() or what=1. >>> >>> That last should be what=1L; the ?'L' is R's way of saying that the >>> whole number should be an integer rather than a numeric. Martin >>>> >>>> Hope that helps. >>>> >>>> Martin >>>>> >>>>> Thanks a lot, >>>>> >>>>> -Gaston >>>>> >>>>> _______________________________________________ Bioconductor >>>>> mailing list Bioconductor at stat.math.ethz.ch >>>>> https://stat.ethz.ch/mailman/listinfo/bioconductor Search the >>>>> archives: >>>>> http://news.gmane.org/gmane.science.biology.informatics.conductor >>>> >>>> >>>>> > _______________________________________________ >>>> >>>> Bioconductor mailing list Bioconductor at stat.math.ethz.ch >>>> https://stat.ethz.ch/mailman/listinfo/bioconductor Search the >>>> archives: >>>> http://news.gmane.org/gmane.science.biology.informatics.conductor >>> >> >>>> >> _______________________________________________ Bioconductor mailing >> list Bioconductor at stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor Search the >> archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor > > -- > James W. MacDonald, M.S. > Biostatistician > Douglas Lab > University of Michigan > Department of Human Genetics > 5912 Buhl > 1241 E. Catherine St. > Ann Arbor MI 48109-5618 > 734-615-7826 > ********************************************************** > Electronic Mail is not secure, may not be read every day, and should not be > used for urgent or sensitive issues > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD REPLY
0
Entering edit mode
@steve-lianoglou-2771
Last seen 21 months ago
United States
Hi, On Thu, Aug 26, 2010 at 12:21 AM, Gaston Fiore <gaston.fiore at="" gmail.com=""> wrote: > Hello everyone, > > By some (strange to me) reason, scan isn't respecting the what argument: > >> temp <- scan(file = "~/data/WT/NS20WTR1ChrReadsF.txt", what = 'integer', sep = ",", quote = 'NULL', comment.char = "") > Read 26042606 items >> class(temp) > [1] "character" >> typeof(temp) > [1] "character" > > I'm new to R, and I apologize if the mistake is obvious, but could someone explain to me why this is the case? What does `head(temp)` give you? -- Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
ADD COMMENT

Login before adding your answer.

Traffic: 611 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6