tidyverse / stringr

A fresh approach to string manipulation in R
https://stringr.tidyverse.org
Other
605 stars 187 forks source link

`str_view()` doesn't function as intended #432

Closed leowill01 closed 2 years ago

leowill01 commented 2 years ago

I was trying to render R4DS to PDF, but the build failed at strings.Rmd with the following error:

Quitting from lines 78-83 (strings.Rmd) 
Error in str_locate(string, pattern) : 
  argument "pattern" is missing, with no default
Calls: local ... withVisible -> eval -> eval -> str_view -> str_locate -> type

Execution halted
Error in Rscript_render(f, render_args, render_meta, add1, add2) : 
  Failed to compile strings.Rmd

So I open the strings.Rmd script and try to execute the following chunk at line 78 (after executing the 2 previous chunks to assign variables):

x <- c(single_quote, double_quote, backslash)
x
str_view(x)

, but it fails with the following error:

[1] "'"  "\"" "\\"
 Error in str_locate(string, pattern) : 
argument "pattern" is missing, with no default

It seems that str_view() isn't able to execute without a second pattern = argument. The documentation for str_view() also shows it as being able to run with only the first argument, but it is not working for me.

This is making it impossible to render R4DS as is, and it seems like I have to replace every str_view() with writeLines() to get the intended output.

Session Info:

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.2.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
 [1] babynames_1.0.1 forcats_0.5.1   stringr_1.4.0   dplyr_1.0.7    
 [5] purrr_0.3.4     readr_2.1.2     tidyr_1.2.0     tibble_3.1.6   
 [9] ggplot2_3.3.5   tidyverse_1.3.1

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.1 xfun_0.29        haven_2.4.3     
 [4] colorspace_2.0-2 vctrs_0.3.8      generics_0.1.2  
 [7] htmltools_0.5.2  yaml_2.2.2       utf8_1.2.2      
[10] rlang_1.0.1      pillar_1.7.0     glue_1.6.1      
[13] withr_2.4.3      DBI_1.1.2        rsthemes_0.3.1  
[16] dbplyr_2.1.1     modelr_0.1.8     readxl_1.3.1    
[19] lifecycle_1.0.1  munsell_0.5.0    gtable_0.3.0    
[22] cellranger_1.1.0 rvest_1.0.2      evaluate_0.14   
[25] knitr_1.37       tzdb_0.2.0       fastmap_1.1.0   
[28] fansi_1.0.2      broom_0.7.12     Rcpp_1.0.8      
[31] scales_1.1.1     backports_1.4.1  jsonlite_1.7.3  
[34] fs_1.5.2         hms_1.1.1        digest_0.6.29   
[37] stringi_1.7.6    bookdown_0.24    grid_4.1.2      
[40] cli_3.1.1        tools_4.1.2      magrittr_2.0.2  
[43] crayon_1.4.2     pkgconfig_2.0.3  ellipsis_0.3.2  
[46] xml2_1.3.3       reprex_2.0.1     lubridate_1.8.0 
[49] assertthat_0.2.1 rmarkdown_2.11   httr_1.4.2      
[52] rstudioapi_0.13  R6_2.5.1         compiler_4.1.2  
hadley commented 2 years ago

You need to install the dev version