ropensci-review-tools / pkgstats

Historical statistics of every R package ever
https://docs.ropensci.org/pkgstats/
17 stars 1 forks source link

Error when trying to run `pkgstats()` #53

Closed pawelru closed 9 months ago

pawelru commented 9 months ago

I'm going through the history of the packages of my interest to better understand the development dynamics etc. I included pkgstats in my workflow and it failed on some historical version of a package.

r$> pkgstats::pkgstats(pkg_git_dir)
Error in if (substring(ptn, 1, 1) == "\\" & substring(ptn, 2, 2) != "\\") { : 
  argument is of length zero

Example is https://github.com/insightsengineering/rtables/commit/9610f634f36944ca18ca933c601665a67ccebcc1 and the issue is in control_parse() on R/tabletrees.R file. The error occurs during the second iteration of a while loop where count is equal to 1. https://github.com/ropensci-review-tools/pkgstats/blob/10a12453a68e918d83d91c8e34ffbf6b924ab71a/R/utils.R#L71-L97

Few debug statements (might be helpful):

r$> ptn
character(0)

r$> g
[[1]]
[1] -1
attr(,"match.length")
[1] -1
attr(,"index.type")
[1] "chars"
attr(,"useBytes")
[1] TRUE

r$> count
[1] 1

r$> out
<simpleError in parse(text = x, keep.source = TRUE, encoding = "UTF-8"): <text>:44:1: unexpected symbol
43: setClass("VNodeInfo", contains = "VIRTUAL", representation(level = "integer", label = "character"))
44: setClass
    ^>
mpadge commented 9 months ago

Thanks @pawelru - could you please tell me which package is causing this? Best way would be to paste a full reprex starting with gert::git_clone(). Please also include packageVersion("pkgstats") as well, to ensure you're using latest version here.

pawelru commented 9 months ago

A minimal reprex example with sessionInfo:

temp_file <- tempfile()
download.file("https://raw.githubusercontent.com/insightsengineering/rtables/9610f634f36944ca18ca933c601665a67ccebcc1/R/tabletrees.R", temp_file)
pkgstats:::control_parse(temp_file)
#> Error in if (substring(ptn, 1, 1) == "\\" & substring(ptn, 2, 2) != "\\") {: argument is of length zero

sessionInfo()
#> R version 4.3.2 (2023-10-31)
#> Platform: aarch64-apple-darwin20 (64-bit)
#> Running under: macOS Ventura 13.5
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib 
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> time zone: Europe/Zurich
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] crayon_1.5.2      vctrs_0.6.4       cli_3.6.1         knitr_1.45       
#>  [5] rlang_1.1.2       xfun_0.41         purrr_1.0.2       styler_1.10.2    
#>  [9] bit_4.0.5         glue_1.6.2        htmltools_0.5.7   hms_1.1.3        
#> [13] fansi_1.0.5       rmarkdown_2.25    R.cache_0.16.0    evaluate_0.23    
#> [17] tibble_3.2.1      tzdb_0.4.0        fastmap_1.1.1     yaml_2.3.7       
#> [21] lifecycle_1.0.3   compiler_4.3.2    fs_1.6.3          pkgconfig_2.0.3  
#> [25] R.oo_1.25.0       R.utils_2.12.2    digest_0.6.33     R6_2.5.1         
#> [29] tidyselect_1.2.0  utf8_1.2.4        reprex_2.0.2      readr_2.1.4      
#> [33] parallel_4.3.2    vroom_1.6.4       pillar_1.9.0      magrittr_2.0.3   
#> [37] R.methodsS3_1.8.2 bit64_4.0.5       tools_4.3.2       withr_2.5.2      
#> [41] pkgstats_0.1.1

Created on 2023-11-16 with reprex v2.0.2

Please tell me if that's enough for you. If you want I can work on an example that involves git clone but obviously it won't be that minimal.

mpadge commented 9 months ago

You've got an older version of pkgstats. Try updating; current verion is 0.1.3.009. Also note that the control_parse() function can and does return errors directly - it is not intended to always work without error, so that alone is not necessarily a problem. When i run your code, control_parse returns an error, but does not itself error on your code.

pawelru commented 9 months ago

Thanks for the help. Upgrading helped and I can successfully complete my function call. I am closing this issue.

Out of curiosity. I was using the most recent version from CRAN - 0.1.1. Any plans for a release?