uribo / zipangu

Japanese utility functions and data
https://uribo.github.io/zipangu
Other
56 stars 7 forks source link

convert_jdate()でNAが含まれるときに失敗する #20

Closed uribo closed 4 years ago

uribo commented 4 years ago

Slackより https://r-wakalang.slack.com/archives/C06QP6NJ0/p1594464408189700

library(zipangu)
date_error <- c("平成30年1月1日", "平成30年2月1日", NA)

date_error %>% 
    convert_jdate()
#> Error in if (sum(sapply(jyear, stringr::str_detect, pattern = "([0-9]{4}|[0-9]{4}.+年)", : missing value where TRUE/FALSE needed

Created on 2020-07-11 by the reprex package (v0.3.0)

yutannihilation commented 4 years ago

とりあえず簡単には sum(, na.rm = TRUE) にすればよさそう?

uribo commented 4 years ago

あれ、そうでしょうか。

とりあえずの打開策

date_error %>% 
  purrr::map_at(which(!is.na(date_error)),
                convert_jdate) %>% 
  purrr::reduce(c)
)

map_at() 的なのを convert_jdate() に組み込むか?

yutannihilation commented 4 years ago

たしかになんかこういうの出てダメでした...

Error: Predicate functions must return a single TRUE or FALSE, not a missing value