PaulMelloy / epiphytoolR

R Package that contains functions which can be used in modelling epiphytotic risk
https://paulmelloy.github.io/epiphytoolR/
Other
2 stars 3 forks source link

format weather example and tests failing #10

Closed PaulMelloy closed 1 year ago

PaulMelloy commented 1 year ago

format_weather() is failing citing that after writing the formated table to csv with write.csv() then reading it back in read.csv() the data now has duplicated times and NA times .

PaulMelloy commented 1 year ago

This occured after updating R to version 4.3

PaulMelloy commented 1 year ago

write.csv simplifies date times on midnight to only the date omiting HH:MM:SS

eg 2023-06-06 00:00:00 becomes 2023-06-06

When read back in and as.POSIXct is used it can't parse correctly and causes NAs

A workaround, for now, is saving with data.table::fwrite() and reading back in with data.table::fread(). 261d624f5ae78a42f9330fd6a4b9f0341cfad8d0 I may have to investigate this further to see if there is a documented method for keeping 00:00:00

PaulMelloy commented 1 year ago

Updating format_weather() with solution in https://stackoverflow.com/questions/37089536/how-can-i-keep-midnight-0000h-using-strptime-in-r

This is a feature of R POSIXt and is documented in the strptime help

format | A character string. The default for the format methods is "%Y-%m-%d %H:%M:%S" if any element has a time component which is not midnight, and "%Y-%m-%d" otherwise. If options("digits.secs") is set, up to the specified number of digits will be printed for seconds.