lindeloev / job

job: free Your RStudio Console
https://lindeloev.github.io/job/
Other
247 stars 8 forks source link

job returns error when using NA_real_ #51

Closed stonekate closed 5 months ago

stonekate commented 1 year ago

Hi Jonas, thanks for such a great package. I have a strange little issue when I try to use NAreal inside dplyr::case_when in job:

library(dplyr)
library(job)

(df <- data.frame(cond = c("a","b","c")))

# works outside job    
mutate(df, item = case_when(cond == "a" ~ 1,
                            cond == "b" ~ 2,
                            cond == "c" ~ NA_real_))

# error inside job
job({mutate(df, item = case_when(cond == "a" ~ 1,
                            cond == "b" ~ 2,
                            cond == "c" ~ NA_real_))})

The traceback suggests NAreal is still being treated as NA, which case_when doesn't like (it needs all assigned values to be of the same type):

grafik

lindeloev commented 1 year ago

Whoa, thanks for posting a nice reproducible example. I don't currently have a nice solution, only an even more minimal replication. All of these lose their type when running in a job:

job::job({
  print(class(NA))
  print(class(NA_real_))
  print(class(NA_character_))
  print(class(NA_integer_))
})
stonekate commented 1 year ago

Curious!

lindeloev commented 5 months ago

@stonekate A bugfix release is up on CRAN and I managed to solve this bug (I hope!).

stonekate commented 5 months ago

nice, thanks!