I'm running R 3.2.1 and stringr 1.0.0 and the following works as expected on my machine. The goal is to extract the number associated with pounds (130), which the following accomplishes on my machine.
x <- "line 4322: He is now 25 years old, and weights 130lbs"
x %>%
str_extract("\\d+(?=lbs)") %>%
as.numeric()
[1] 130
Again, this works fine on my machine. However, on a friends PC, it does not and the perl()
function has been deprecated.
So, the goal is to continue with the stringr
package but add the proper options so that it is PCRE compatible. These two posts, Post 1 and Post 2, address the issue, but they use base
functions and I want to preserve the workflow I have with stringr
.
This code is a possible solution, but I'm not sure if will work as expected on another machine.
x %>%
str_extract(regex("\\d+(?=lbs)", perl = T)) %>%
as.numeric()
[1] 130