Closed hadley closed 9 years ago
Thanks for the heads up Hadley. Problem is fixed in the 2D branch on Github. I will send to CRAN after you send the new stringr
. Problem appears to have been, I think, that str_locate_all
used to return an empty list if no matches were found, and the dev version returns NA
. At least, that's what it looks like from here.
Oh that's definitely a bug. It should be returning an empty list - could you try making a minimal reprex somewhere please?
Here is a MWE, but I cannot replicate the behavior. I went back several stringr
versions and they all return NA
if no match is found, so I'm a little lost. In Example 1, the code was checking for an empty list, because at one point that worked. LindenmayeR
was just written back in August, so I can't figure it out. Maybe it will be clear to you. Bryan
rules <- data.frame(inp = c("A", "B"), out = c("B-A-B", "A+B+A"), stringsAsFactors = FALSE)
init <- "A"
RR <- vector("list") # save the rule output here
# Example 1. This is the newer version, changed today, on branch 2D
for (i in 1:nrow(rules)) {
rr <- str_locate_all(init, rules[i,1])
if (is.na(rr[[1]][1,1])) {
next # no match, skip and keep going
}
RR[i] <- rr
}
# Example 2. Previous/Original version
for (i in 1:nrow(rules)) {
rr <- str_locate_all(init, rules[i,1])
if (dim(rr[[1]])[1] == 0) {
next # no match, skip and keep going
# This was a way of checking for an empty list
}
RR[i] <- rr
}
# The 'correct' answer is
# RR
# [[1]]
# start end
# [1,] 1 1
# Old version of stringr (0.6.2) gives this answer for Example 1 and 2
# RR
# [[1]]
# start end
# [1,] 1 1
# [[2]]
# start end
# [1,] NA NA
Dev version (stringr_0.9.0.9000) gives the same answers! so do 0.6.1, 0.6. 0.5
Oops, I used FALSE
in a couple of places where I should've used TRUE
.Fixed now!
So no match will return an empty list element? Thanks, Bryan
On Dec 10, 2014, at 5:16 PM, Hadley Wickham notifications@github.com wrote:
Oops, I used FALSE in a couple of places where I should've used TRUE.Fixed now!
— Reply to this email directly or view it on GitHub.
It returns a zero-row matrix - i.e. there's always one row per match
Could you please explore? This may be an accident change in behaviour in stringr, or more consistent stringr code might have revealed a bug in your code.
The easiest way to fix the notes is to add
import(grid)
to your namespace. (Or prefix each call to a grid function withgrid::
)