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

str_trunc can't handle NA's in input #162

ClaytonJY opened this issue May 9, 2017 · 0 comments

str_trunc can't handle NA's in input #162

ClaytonJY opened this issue May 9, 2017 · 0 comments


Copy link

@ClaytonJY ClaytonJY commented May 9, 2017

Passing a single NA into str_trunc leaves it untouched, as expected

NA_character_ %>% str_trunc(10)

But a vector with one or more NA's throws an error

c("foo bar baz", NA) %>% str_trunc(10)
c(NA_character_, NA_character_) %>% str_trunc(10)

Error in string[too_long] <- switch(side, right = str_c(str_sub(string[too_long], :
NAs are not allowed in subscripted assignments

which happens without piping, as well.

It seems like the expected behaviour would be to truncate the "real" strings, and leave the NA's untouched, rather than throw an error.

Session Info

> devtools::session_info()
Session info ----------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.4.0 (2017-04-21)
 system   x86_64, linux-gnu           
 ui       RStudio (1.0.143)           
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/New_York            
 date     2017-05-09                  

Packages --------------------------------------------------------------------------------------------------------------------------------
 package  * version date       source        
 devtools   1.12.0  2016-12-05 CRAN (R 3.4.0)
 digest     0.6.12  2017-01-27 CRAN (R 3.4.0)
 magrittr * 1.5     2014-11-22 CRAN (R 3.4.0)
 memoise    1.1.0   2017-04-21 CRAN (R 3.4.0)
 stringi    1.1.5   2017-04-07 CRAN (R 3.4.0)
 stringr  * 1.2.0   2017-02-18 CRAN (R 3.4.0)
 withr      1.0.2   2016-06-20 CRAN (R 3.4.0)

(Not the dev version, but git blame suggests this function hasn't changed in two years)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant