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
>>>>> Loris Bennett <loris.bennett at fu-berlin.de> >>>>> on Mon, 8 Aug 2016 14:12:47 +0200 writes:> 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, >> >> Loris > Continuing 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 Well, let me argue that you should have found this to be a *helpful* error message. You are no complete beginner anymore, right, so 1) the error is in your use of as.difftime(). 2) ?as.difftime or str(difftime) both clearly indicate that 'tim' is the first argument of as.difftime, and I really do wonder why you continued with the infamous "trial-and-error programming technique" instead of reading or at least quickly browsing the relevant reference, i.e., help page Martin > 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
Martin Maechler <maechler at stat.math.ethz.ch> writes:>>>>>> Loris Bennett <loris.bennett at fu-berlin.de> >>>>>> on Mon, 8 Aug 2016 14:12:47 +0200 writes: > > > 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, > >> > >> Loris > > > Continuing 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 > > Well, let me argue that you should have found this to be a *helpful* > error message. You are no complete beginner anymore, right, > so > > 1) the error is in your use of as.difftime(). > > 2) ?as.difftime or str(difftime) > both clearly indicate that 'tim' is the first argument of as.difftime, > > and I really do wonder why you continued with the infamous > "trial-and-error programming technique" instead of reading or at > least quickly browsing the relevant reference, i.e., help page > > MartinMy apologies, you are absolutely right - I see the error of my ways. The only feeble defence I can mount is that the usage example from ?as.difftime as.difftime(tim, format = "%X", units = "auto") superficially disguises the fact that the first argument is also a named argument with the name 'tim'. I think I had assumed that the initial argument were always positional, e.g. as for paste0 paste0(..., collapse = NULL) However, I now realise that '...' also generates named arguments, e.g. paste0(..1='a',..2='b') So as a non-beginner but infrequent R user, in future I shall try use the explicit form more often, e.g. as.difftime(tim = "4-03:02:01", format = "%d-%H:%M:%S") to remind myself what I am doing. So fortune(350) really is true. I just didn't believe enough to read enough. Loris -- Dr. Loris Bennett (Mr.) ZEDAT, Freie Universit?t Berlin Email loris.bennett at fu-berlin.de