Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid timezone of the input vector: "GMT" using Linear relations between pollutants function #263

Closed
cross85 opened this issue Jul 20, 2021 · 5 comments

Comments

@cross85
Copy link

cross85 commented Jul 20, 2021

I was checking the linear relation between pollutants function with the test data and I've got this error message:

Error: Problem with `mutate()` column `cond`.
i `cond = round_date(date, period)`.
x CCTZ: Invalid timezone of the input vector: "GMT"

After that I run rlang::last_error() and I get this message:

<error/dplyr:::mutate_error>
Problem with `mutate()` column `cond`.
i `cond = round_date(date, period)`.
x CCTZ: Invalid timezone of the input vector: "GMT"

Then I checked the backtrace rlang::last_trace()

<error/dplyr:::mutate_error>
Problem with `mutate()` column `cond`.
i `cond = round_date(date, period)`.
x CCTZ: Invalid timezone of the input vector: "GMT"
Backtrace:
     x
  1. +-openair::linearRelation(mydata, x = "nox", y = "so2")
  2. | +-mutate(mydata, cond = round_date(date, period)) %>% group_by(cond)
  3. | +-dplyr::mutate(mydata, cond = round_date(date, period))
  4. | \-dplyr:::mutate.data.frame(mydata, cond = round_date(date, period))
  5. |   \-dplyr:::mutate_cols(.data, ..., caller_env = caller_env())
  6. |     +-base::withCallingHandlers(...)
  7. |     \-mask$eval_all_mutate(quo)
  8. +-dplyr::group_by(., cond)
  9. +-lubridate::round_date(date, period)
 10. | +-base::as.POSIXct(ceiling_date(x, unit = unit, week_start = week_start))
 11. | \-lubridate::ceiling_date(x, unit = unit, week_start = week_start)
 12. |   +-stats::update(x, seconds = second(x) - 1e-05, simple = T)
 13. |   \-lubridate:::update.POSIXt(x, seconds = second(x) - 1e-05, simple = T)
 14. |     +-base::do.call(...)
 15. |     \-(function (object, years = integer(), months = integer(), days = integer(), ...
 16. |       +-lubridate::reclass_date(do.call(C_update_dt, updates), object)
 17. |       +-lubridate:::reclass_date.POSIXct(...)
 18. |       | \-base::as.POSIXct(new)
 19. |       +-base::do.call(C_update_dt, updates)
 20. |       \-(function (dt, year, month, yday, mday, wday, hour, minute, second, ...
 21. +-base::stop(...)
 22. \-(function (e) ...
<error/Rcpp::exception>
CCTZ: Invalid timezone of the input vector: "GMT"

I'm using R 4.1.0 and openair 2.8-3
I tried using my own data and I've got the same error message
I just updated to the latest versions of R and openair, is this some incompatibility or some bug on the openair script?

@davidcarslaw
Copy link
Owner

Strange. Works for me OK. Have you updated all other packages through update.packages()? I get:

openair::linearRelation(mydata, x = "nox", y = "so2")

image

@cross85
Copy link
Author

cross85 commented Jul 21, 2021

I did update.packages() but I think nothing related to openair was updated.
The problem is when "GMT" is set. As example.

If I import the data this wasy, I have no problem:

PM10 <- read_delim("PM10.csv", ";", escape_double = FALSE, 
col_types = cols(date = col_datetime(format = "%d/%m/%Y %H:%M")), trim_ws = TRUE)

But If I import the data with no format, and I apply it after with GMT as time zone, I get the error message.

PM10 <- read_delim("PM10.csv", ";", escape_double = FALSE, trim_ws = TRUE)
PM10$date <- as.POSIXct(strptime(PM10$date, format = "%d/%m/%Y %H:%M", "GMT"))

@davidcarslaw
Copy link
Owner

mmm ... yes. I think this is something to do with how lubridate handles base R times. Does this work:

library(lubridate)
PM10$date <- dmy_hm(PM10$date, tz = "GMT"))

@cross85
Copy link
Author

cross85 commented Jul 22, 2021

I think maybe it's lubridate problem. I found this issue checking on lubridate, it might be that library issue, apparently with the folder where the time zones are stored. #928

I tried what you said and I've got the same error messages. So, for now I will use it without setting a time zone.

> library(readr)
> PM10 <- read_delim("PM10.csv", 
+     ";", escape_double = FALSE, trim_ws = TRUE)
> library(lubridate)

Attaching package: ‘lubridate’

The following objects are masked from ‘package:base’:

    date, intersect, setdiff, union

> PM10$date <- dmy_hm(PM10$date, tz = "GMT")
> str(PM10)
spec_tbl_df [8,712 x 10] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
 $ date   : POSIXct[1:8712], format: "2019-01-01 01:00:00" "2019-01-01 02:00:00" "2019-01-01 03:00:00" "2019-01-01 04:00:00"
> library(openair)
> openair::linearRelation(PM10, x = "PM10_LC", y = "PM10_CH")
Error: Problem with `mutate()` column `cond`.
i `cond = round_date(date, period)`.
x CCTZ: Invalid timezone of the input vector: "GMT"
Run `rlang::last_error()` to see where the error occurred.

I'm using this version of R and openair 2.8-3 in windows with RStudio and lubridate 1.7.10

R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

@jack-davison
Copy link
Collaborator

Closing as this appeared to be an issue with the {lubridate} package; if your issue is persisting do feel free to reopen and we'll take another look. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants