Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autotest parses "M"/"F" in examples as logical, not character #86

Open
simpar1471 opened this issue Feb 5, 2024 · 0 comments
Open

autotest parses "M"/"F" in examples as logical, not character #86

simpar1471 opened this issue Feb 5, 2024 · 0 comments

Comments

@simpar1471
Copy link
Contributor

I'm working on a package at the minute where functions have a sex argument, specified either by an upper case "M" or upper-case "F". When running autotest on this package, it treats the sex argument as logical, even though sex only accepts character input in the roxygen examples. This causes expect_autotest_no_err(autotest_package()) to fail, when it would otherwise pass.

I'll demonstrate the issue with some simple functions. These functions take two input strings, and paste0() them together. The only difference between them is in the roxygen @examples sections:

#' Check autotest for GitHub issue ("A"/"B")
#' @param arg_1 Single-length character vector.
#' @param arg_2 Single-length character vector.
#' @examples
#' # Try with "T"
#' foo(arg_1 = "A", arg_2 = "B")
#' @export
foo <- function(arg_1, arg_2) {
  checkmate::qassert(arg_1, "S1")
  checkmate::qassert(arg_2, "S1")
  paste0(arg_1, arg_2)
}

#' Check autotest for GitHub issue ("M")
#' @param arg_1 Single-length character vector.
#' @param arg_2 Single-length character vector.
#' @examples
#' # Try with "T"
#' bar(arg_1 = "A", arg_2 = "T")
#' @export
bar <- function(arg_1, arg_2) {
  checkmate::qassert(arg_1, "S1")
  checkmate::qassert(arg_2, "S1")
  paste0(arg_1, arg_2)
}

#' Check autotest for GitHub issue ("F")
#' @param arg_1 Single-length character vector.
#' @param arg_2 Single-length character vector.
#' @examples
#' # Try with "F"
#' qux(arg_1 = "F", arg_2 = "B")
#' @export
qux <- function(arg_1, arg_2) {
  checkmate::qassert(arg_1, "S1")
  checkmate::qassert(arg_2, "S1")
  paste0(arg_1, arg_2)
}

After using devtools::document() and devtools::load_all() to make them available to autotest, running autotest::examples_to_yaml(package = ".", c("foo", "bar", "qux")) makes the following output:

$foo
[1] "package: gigs"             
[2] "functions:"                
[3] "    - foo:"                
[4] "        - parameters:"     
[5] "            - arg_1: \"A\""
[6] "            - arg_2: \"B\""
attr(,"package")
[1] "."

$bar
[1] "package: gigs"             
[2] "functions:"                
[3] "    - bar:"                
[4] "        - parameters:"     
[5] "            - arg_1: \"A\""
[6] "            - arg_2: \"T\""
attr(,"package")
[1] "."

$qux
[1] "package: gigs"             
[2] "functions:"                
[3] "    - qux:"                
[4] "        - parameters:"     
[5] "            - arg_1: \"F\""
[6] "            - arg_2: \"B\""
attr(,"package")
[1] "."

When I autotest these functions, the resulting output has errors for bar() and qux(), but not foo(). These errors specifically come from trying to treat arg_2 in bar() and arg_1 in qux() as single logical values, instead of as single strings.

autotest::autotest_package(functions = c("foo", "bar", "qux"), test = TRUE)
# A tibble: 25 x 9
   type       test_name fn_name parameter parameter_type operation content test  yaml_hash
   <chr>      <chr>     <chr>   <chr>     <chr>          <chr>     <chr>   <lgl> <chr>    
 1 error      NA        bar     NA        NA             normal f~ ":quot~ TRUE  b3a1d9a3~
 2 error      negate_l~ bar     arg_2     single logical Negate d~ ":quot~ TRUE  b3a1d9a3~
 3 error      negate_l~ bar     arg_2     single logical Negate d~ ":quot~ TRUE  b3a1d9a3~
 4 error      return_s~ bar     (return ~ (return objec~ error fr~ "Asser~ TRUE  b3a1d9a3~
 5 error      NA        qux     NA        NA             normal f~ ":quot~ TRUE  fffd053f~
 6 error      negate_l~ qux     arg_1     single logical Negate d~ ":quot~ TRUE  fffd053f~
 7 error      negate_l~ qux     arg_1     single logical Negate d~ ":quot~ TRUE  fffd053f~
 8 error      return_s~ qux     (return ~ (return objec~ error fr~ "Asser~ TRUE  fffd053f~
 9 diagnostic single_c~ bar     arg_1     single charac~ lower-ca~ "is ca~ TRUE  b3a1d9a3~
10 diagnostic single_c~ bar     arg_1     single charac~ upper-ca~ "is ca~ TRUE  b3a1d9a3~
# i 15 more rows
# i Use `print(n = ...)` to see more rows

My guess is that autotest is parsing the upper-case "F" and "T" arguments as the F/T symbols for FALSE/TRUE, and mutating them accordingly. This is making autotest fail where it shouldn't.

sessionInfo()

Click for details
sessionInfo()
R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

Matrix products: default


locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

time zone: Europe/London
tzcode source: internal

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

other attached packages:
[1] gigs_0.4.0        withr_2.5.2       units_0.8-5       testthat_3.2.1   
[5] rmarkdown_2.25    knitr_1.45        vctrs_0.6.5       checkmate_2.3.1  
[9] gamlss.dist_6.1-1

loaded via a namespace (and not attached):
[1] remotes_2.4.2.1       rlang_1.1.3           magrittr_2.0.3       
[4] compiler_4.3.2        roxygen2_7.3.0        callr_3.7.3          
[7] stringr_1.5.1         profvis_0.3.8         pkgconfig_2.0.3      
[10] fastmap_1.1.1         backports_1.4.1       ellipsis_0.3.2       
[13] utf8_1.2.4            promises_1.2.1        sessioninfo_1.2.2    
[16] ps_1.7.5              purrr_1.0.2           waldo_0.5.2          
[19] xfun_0.41             cachem_1.0.8          growthstandards_0.1.6
[22] later_1.3.2           R6_2.5.1              stringi_1.8.3        
[25] pkgload_1.3.3         brio_1.1.4            Rcpp_1.0.12          
[28] usethis_2.2.2         httpuv_1.6.13         tidyselect_1.2.0     
[31] rstudioapi_0.15.0     yaml_2.3.8            miniUI_0.1.1.1       
[34] processx_3.8.3        pkgbuild_1.4.3        lattice_0.21-9       
[37] tibble_3.2.1          shiny_1.8.0           evaluate_0.23        
[40] desc_1.4.3            urlchecker_1.0.1      xml2_1.3.6           
[43] pillar_1.9.0          generics_0.1.3        rprojroot_2.0.4      
[46] ggplot2_3.4.4         munsell_0.5.0         commonmark_1.9.0     
[49] scales_1.3.0          xtable_1.8-4          glue_1.7.0           
[52] tools_4.3.2           srr_0.0.1.194         data.table_1.14.10   
[55] fs_1.6.3              grid_4.3.2            devtools_2.4.5       
[58] colorspace_2.1-0      cli_3.6.2             fansi_1.0.6          
[61] dplyr_1.1.4           autotest_0.0.2.204    gtable_0.3.4         
[64] digest_0.6.34         htmlwidgets_1.6.4     memoise_2.0.1        
[67] htmltools_0.5.7       lifecycle_1.0.4       mime_0.12            
[70] MASS_7.3-60          
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant