1

I updated my r to 4.2.1 and I ran into this error with epiweek. epiweek is a lubridate function before the update, but it may be changed now to the package grate, causing the problem. Please see below Please let me know how to create the lubridate::epiweek function with the grate package or any other packages:functions. Thanks!

dataset$epi_week <- str_pad(epiweek(dataset$epi_date_V3),2,pad="0")

Error in epiweek(dataset$epi_date_V3) : year must be integer.

akrun
  • 874,273
  • 37
  • 540
  • 662
merry123
  • 103
  • 5
  • 1
    What does `class(dataset$epi_date_V3)` return? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Apr 06 '23 at 15:25
  • Can you show a small reprodcuible example with `dput` i.e. `dput(head(dataset$epi_date_V3))` – akrun Apr 06 '23 at 15:26
  • > dput(head(dataset$epi_date_V3)) structure(c(19210, 19191, 19209, 19217, 19239, 19276), class = "Date") – merry123 Apr 06 '23 at 15:37
  • class(dataset$epi_date_V3) is date – merry123 Apr 06 '23 at 15:37
  • @merry123 it is not showing any error with your dput. Can you show the package versions of lubridate and stringr – akrun Apr 06 '23 at 15:39
  • lubridate_1.9.2 , stringr_1.5.0 – merry123 Apr 06 '23 at 15:43
  • btw, what does str_pad function do? Can I omit it? – merry123 Apr 06 '23 at 15:46
  • @merry123 It just prefix 0's to those values less than 10 thus, 9 will be '09' i.e. just a formatting of the numbers to two digits – akrun Apr 06 '23 at 15:48
  • I used the `lubridate` 1.9.1. Maybe that is the only difference – akrun Apr 06 '23 at 15:49
  • did you use stringr_1.5.0? – merry123 Apr 06 '23 at 15:51
  • I used stringr 1.5.0 on R 4.2.3. I am updating the lubridate for checking again – akrun Apr 06 '23 at 15:52
  • It is working fine with the new lubridate version 1.9.2 as well. `v1 <- structure(c(19210, 19191, 19209, 19217, 19239, 19276), class = "Date");str_pad(epiweek(v1),2,pad="0") [1] "31" "29" "31" "32" "36" "41"` – akrun Apr 06 '23 at 15:53
  • so you were able to do the str_pad function with the epiweek function inside? – merry123 Apr 06 '23 at 15:58
  • @merry123 yes, it is working fine for me – akrun Apr 06 '23 at 15:59
  • FWIW the `stringr` version should be irrelevant. The error is coming from the `epiweek` function. @merry123 can you please try `library(lubridate); packageVersion("lubridate"); v1 <- structure(c(19210, 19191, 19209, 19217, 19239, 19276), class = "Date"); epiweek(v1); sessionInfo()` in a **clean** R session and edit your question to include the output, in a text format (cut-and-paste to a code block rather than including a screenshot)? And also the results of `year(as.POSIXlt(v1))`? – Ben Bolker Apr 06 '23 at 16:16

0 Answers0