http://www.dummies.com/how-to/content/how-to-read-errors and-warnings-in-r.html If something goes wrong with your code, R tells you. We have to admit it: These error messages can range from mildly confusing to completely incomprehensible if you?re not used to them. fortune(350) regarding the on-line help is also inspiring You need to get the hang of reading the online help. The information required is actually therein ?dotchart --- it's just tersely and obscurely expressed. A certain degree of optimism is required. You need to ***believe*** that the information is there; then ask yourself "What could they possibly mean by what they have written that would tell me what I need to know?". -- Rolf Turner (on reading the help pages) R-help (June 2013) John Kane Kingston ON Canada> -----Original Message----- > From: loris.bennett at fu-berlin.de > Sent: Mon, 8 Aug 2016 12:07:43 +0200 > To: r-help at stat.math.ethz.ch > Subject: Re: [R] No "number of days" format for 'difftime'? > > Hi, > > I was probably misled by the, to my mind, esoteric error message into > thinking the error was more subtle. Something like "unmatched quotes" > might have helped me recognise that I was just being dopey. > > Thanks to John and Rui. > > Loris > > <ruipbarradas at sapo.pt> writes: > >> Hello, >> >> You're missing a double quotes. Right after format>> >> Hope this helps, >> >> Rui Barradas >> >> >> Citando Loris Bennett <loris.bennett at fu-berlin.de>: >> >>> Hi, >>> >>> When I try >>> >>> d <- as.difftime("6-08:18:33",format=%d-%H:%M:%S") >>> >>> I get: >>> >>> Error: unexpected SPECIAL in "as.difftime("6-08:18:33",format=%d-%" >>> >>> Am I correct in thinking that it is not possible to do something like >>> this, because there is no character string for the format which >>> corresponds to "number of days"? >>> >>> I could misuse "%j" for "day of the year as a decimal number", but >>> ultimately the "difftime" object is still a data, rather than a length >>> of time and I should be looking at a package like 'lubridate' instead. >>> Is that the case? >>> >>> Cheers, >>> >>> Loris >>> >>> -- >>> Dr. Loris Bennett (Mr.) >>> ZEDAT, Freie Universit?t Berlin? ? ? ? ?Email >>> loris.bennett at fu-berlin.de >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.htmland provide commented, >>> minimal, self-contained, reproducible code. >> >> >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. > > -- > Dr. Loris Bennett (Mr.) > ZEDAT, Freie Universit?t Berlin Email loris.bennett at fu-berlin.de > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Thanks for the link, John. However, there is a hyphen missing. It should be: http://www.dummies.com/how-to/content/how-to-read-errors-and-warnings-in-r.html Appropriately, with the correct URL we find the too often forgotten pearl of wisdom: "Chances are, you just typed something wrong there." I think I need this on my coffee cup. Cheers, Loris John Kane <jrkrideau at inbox.com> writes:> http://www.dummies.com/how-to/content/how-to-read-errors and-warnings-in-r.html> If something goes wrong with your code, R tells you. We have to admit > it: These error messages can range from mildly confusing to completely > incomprehensible if you?re not used to them. > > > fortune(350) regarding the on-line help is also inspiring > > You need to get the hang of reading the online help. The information > required is actually therein ?dotchart --- it's just tersely and > obscurely expressed. A certain degree of optimism is required. You > need to ***believe*** that the information is there; then ask yourself > "What could they possibly mean by what they have written that would > tell me what I need to know?". > -- Rolf Turner (on reading the help pages) > R-help (June 2013) > > > John Kane > Kingston ON Canada > > >> -----Original Message----- >> From: loris.bennett at fu-berlin.de >> Sent: Mon, 8 Aug 2016 12:07:43 +0200 >> To: r-help at stat.math.ethz.ch >> Subject: Re: [R] No "number of days" format for 'difftime'? >> >> Hi, >> >> I was probably misled by the, to my mind, esoteric error message into >> thinking the error was more subtle. Something like "unmatched quotes" >> might have helped me recognise that I was just being dopey. >> >> Thanks to John and Rui. >> >> Loris >> >> <ruipbarradas at sapo.pt> writes: >> >>> Hello, >>> >>> You're missing a double quotes. Right after format>>> >>> Hope this helps, >>> >>> Rui Barradas >>> >>> >>> Citando Loris Bennett <loris.bennett at fu-berlin.de>: >>> >>>> Hi, >>>> >>>> When I try >>>> >>>> d <- as.difftime("6-08:18:33",format=%d-%H:%M:%S") >>>> >>>> I get: >>>> >>>> Error: unexpected SPECIAL in "as.difftime("6-08:18:33",format=%d-%" >>>> >>>> Am I correct in thinking that it is not possible to do something like >>>> this, because there is no character string for the format which >>>> corresponds to "number of days"? >>>> >>>> I could misuse "%j" for "day of the year as a decimal number", but >>>> ultimately the "difftime" object is still a data, rather than a length >>>> of time and I should be looking at a package like 'lubridate' instead. >>>> Is that the case? >>>> >>>> Cheers, >>>> >>>> Loris >>>> >>>> -- >>>> Dr. Loris Bennett (Mr.) >>>> ZEDAT, Freie Universit?t Berlin? ? ? ? ?Email >>>> loris.bennett at fu-berlin.de >>>> >>>> ______________________________________________ >>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>> PLEASE do read the posting guide >>>> http://www.R-project.org/posting-guide.htmland provide commented, >>>> minimal, self-contained, reproducible code. >>> >>> >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> 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. >> >> -- >> Dr. Loris Bennett (Mr.) >> ZEDAT, Freie Universit?t Berlin Email loris.bennett at fu-berlin.de >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. > > ____________________________________________________________ > FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop! > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.-- Dr. Loris Bennett (Mr.) ZEDAT, Freie Universit?t Berlin Email loris.bennett at fu-berlin.de
Loris Bennett <loris.bennett at fu-berlin.de> writes:> Thanks for the link, John. However, there is a hyphen missing. It > should be: > > http://www.dummies.com/how-to/content/how-to-read-errors-and-warnings-in-r.html > > Appropriately, with the correct URL we find the too often forgotten > pearl of wisdom: > > "Chances are, you just typed something wrong there." > > I think I need this on my coffee cup. > > Cheers, > > LorisContinuing the topic for my future self and others equally poorly versed in The Art and Dark Science of Interpreting R Error Messages, if I have the following in the file "my_data" 1094165 2016-07-24T09:40:02 13-23:03:28 1 COMPLETED 1112076 2016-08-01T14:45:49 6-13:26:15 1 COMPLETED and do> d <- read.table("my_data") > colnames(d) <- c("jobid","start","elapsed","alloccpus","state") > df <- transform(d,start = as.POSIXct(start,format="%Y-%m-%dT%H:%M:%S"),elapsed = as.difftime(elapsed,format="%d-%H:%M:%S"))I get the following: Error in as.difftime(elapsed, format = "%d-%H:%M:%S") : 'tim' is not character or numeric Remembering that if something is not what you think it is, it is probably a factor, I find that> d <- read.table(data_file,stringsAsFactors=FALSE)causes the error to go away. So what's all this 'tim' business? A quick squint at the source code of datetime.R reveals the following line: if (!is.numeric(tim)) stop("'tim' is not character or numeric") So the error message tells me something about the arbitrary name of the variable 'tim', which could also have been 'tom', 'dick', or 'harriet', but nothing about the value. So follow Rolf Turner's fortune(350) advice, then look at the source code, and then realise that you weren't being totally dopey in not understanding the error message. Loris -- Dr. Loris Bennett (Mr.) ZEDAT, Freie Universit?t Berlin Email loris.bennett at fu-berlin.de