str_replace should ignore NA when using function as replacement#164
str_replace should ignore NA when using function as replacement#164hadley merged 11 commits intotidyverse:masterfrom
Conversation
|
Is this now in CRAN stringi? |
|
Should be anytime soon, the new release of stringi got stuck in CRAN/incoming since Friday |
|
Great - @yutannihilation can you please include the stringi version requirement in the DESCRIPTION? |
3a688b4 to
d0c8abf
Compare
|
Thanks. I updated the version requirement to 1.1.6. https://github.com/gagolews/stringi/releases/tag/v1.1.6. |
R/sub.r
Outdated
| #' matrix to `start`. | ||
| #' | ||
| #' Negative values count backwards from the last character. | ||
| #' @param omit_na single logical value; if \code{TRUE}, missing values in any of the arguments |
There was a problem hiding this comment.
Can you please switch to markdown formatting?
R/sub.r
Outdated
| #' | ||
| #' Negative values count backwards from the last character. | ||
| #' @param omit_na single logical value; if \code{TRUE}, missing values in any of the arguments | ||
| #' provided will result in an unchanged input; replacement function only |
There was a problem hiding this comment.
I think you can remove the bit about replacement function only. It would be useful to have a bit more motivation about when this is useful
|
Should I also add stringi to Remotes? Or can I just wait the release of 1.1.6? |
|
Add to remotes just so we can test it, and I'll remove before releasing stringr. |
|
Thanks, I've added Remotes. Travis passes but AppVeyor fails to install stringi by this error. Needs to investigate later.
|
|
Looks good. Can you please add a bullet to NEWS? It should briefly describe the change (starting with name of the function), and crediting yourself with |
|
Thanks! I've done. I think this is ready to merge now. |
|
Congratulations for the release of stringi 1.1.6! 🎉 |
|
@hadley Hi, do I need to make further improvements on this PR? (Just curious, I know it's a bit too late since the next version is already submitted to CRAN) |
|
Unless it gets rejected by CRAN, it'll need to go in the next version. Sorry for forgetting about it 😢 |
|
No problem. Sorry for taking some time to get this PR ready. I will try to do better next time 😉 |
|
Luckily for you, stringr did get rejected, so I can merge this 😄 |
|
Wow, I appreciate the luck. Thanks! |
error.
I remember seeing this error at the BSD workshop back in April 2019,
but had no idea what was causing it. I happened to reproduce it
when in the RStudio Server hosted in the Docker image rocker/verse
(I wanted to test the httpuv error with the Viewer pane). I got
the same error message as some of the students:
wflow_start("test")
Error: evaluation nested too deeply: infinite recursion /
options(expressions=)?
Error during wrapup: evaluation nested too deeply: infinite recursion /
options(expressions=)?
It happened no matter the directory, or using the RStudio project
template.
The error was caused by the recursive function
obtain_existing_path(). It didn't have a stop criteria if it was
passed nonsense like NA, so it went on recursively until it errored.
The NA came from absolute() -> toupper_win_drive(). stringr 1.2.0
introduced the ability to use a function to perform the replacement.
This is how toupper_win_drive() works, it uses toupper. The problem
is that if there is no match, instead of returning the original
string, it returns NA.
This was fixed in stringr 1.3.0 in PR #164. The NEWS bullet is
quite subtle for how much it changes the behavior.
tidyverse/stringr#164
I like
str_replace()with function replacement. It's a very cool feature.One thing, currently, the code bellow returns a vector contains
NA:But, I feel this is a bit counter-intuitive and not consistent with the results of similar functions:
This PR will
omit_naoption tostr_sub(), whichstri_sub<-()got in response to stri_sub<- should silently ignore NA locations gagolews/stringi#199 and I'm trying to extend in "omit_na=TRUE" keeps the string as is if the replacement is NA gagolews/stringi#268.str_replace()to ignoreNAand keep the original.Note that, test will pass only after gagolews/stringi#268 will be merged.