1

I am using read.zoo to read tab-separated datafiles into a zoo time series. I have the following code:

z <- read.zoo("poolBL03GD04_842_WMO_03862.tts", index=2:5, FUN = conv)

As far as I understand, this is assigning the result of the read.zoo function to the z variable, but it prints out the entire result of read.zoo as well. Why is this, and how can I stop it?

Updated with reproducible example:

library(chron)
library(zoo)

conv <- function(y,m,d,t) {
  date_str <- paste(m,"/", d, "/", y, " ", sep="")
  time_str <- paste(t, ":00", sep="")
  print(date_str)
  print(time_str)
  chron(date_str, time_str)
}

zz <- textConnection("51645  2000 04 11  00:00  2367.35   80.9   12.5
51645  2000 04 11  01:00  2370.38   88.8   13.7
51645  2000 04 11  02:00  2357.50   80.6   12.5
51645  2000 04 11  03:00  2360.38   87.2   13.5
51645  2000 04 11  04:00  2354.70   84.0   12.9
51645  2000 04 11  05:00  2345.91   79.3   12.2")
z <- read.zoo(zz, index=2:5, FUN = conv, header=F)

This is even more frustrating when trying to use read.zoo from within a function.

Does anyone have any idea why this is happening?

robintw
  • 27,571
  • 51
  • 138
  • 205

2 Answers2

5

Comment the print lines in your conv function.

conv <- function(y,m,d,t) {
  date_str <- paste(m,"/", d, "/", y, " ", sep="")
  time_str <- paste(t, ":00", sep="")
#  print(date_str)
#  print(time_str)
  chron(date_str, time_str)
}
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
1

I don't know much about zoo, but it's worth noting that you can use capture.output to force anything to send it's output to a variable.

frankc
  • 11,290
  • 4
  • 32
  • 49