ropensci-review-tools / autotest

Automatic testing of R packages
https://docs.ropensci.org/autotest
54 stars 5 forks source link

Error in yaml::yaml.load(i): Parser error #49

Open vgherard opened 3 years ago

vgherard commented 3 years ago

Here I'm trying autotest::autotest_package() on kgrams (I'm using here the CRAN version for ease of reproducibility). It looks like it is failing to convert some of my examples to YAML, but the errors are somewhat cryptic. Might these be due to the fact that some of my examples contain infix operators (e.g. %|%)? I recall having some problems also with pkgdown for this reason.

I will try to jump into the debugger to catch the culprit example(s?). Meanwhile, any idea on this?

Thanks, Valerio

autotest::autotest_package(package = "kgrams")
#> ٭ Extracting example code from 14 .Rd files
#>   |                                                                              |                                                                      |   0%  |                                                                              |=====                                                                 |   7%  |                                                                              |==========                                                            |  14%  |                                                                              |===============                                                       |  21%  |                                                                              |====================                                                  |  29%  |                                                                              |=========================                                             |  36%  |                                                                              |==============================                                        |  43%  |                                                                              |===================================                                   |  50%  |                                                                              |========================================                              |  57%  |                                                                              |=============================================                         |  64%
#> Error in qstart[i]:qend[i]: Argomento NA/NaN
autotest::autotest_package(package = "kgrams", exclude = "preprocess")
#> ٭ Extracting example code from 13 .Rd files
#>   |                                                                              |                                                                      |   0%  |                                                                              |=====                                                                 |   8%  |                                                                              |===========                                                           |  15%  |                                                                              |================                                                      |  23%  |                                                                              |======================                                                |  31%  |                                                                              |===========================                                           |  38%  |                                                                              |================================                                      |  46%  |                                                                              |======================================                                |  54%  |                                                                              |===========================================                           |  62%  |                                                                              |================================================                      |  69%  |                                                                              |======================================================                |  77%  |                                                                              |===========================================================           |  85%  |                                                                              |=================================================================     |  92%  |                                                                              |======================================================================| 100%
#> ✓ Extracted example code
#> ٭ Converting 10 examples to yaml
#>   |                                                                              |                                                                      |   0%  |                                                                              |=======                                                               |  10%  |                                                                              |==============                                                        |  20%  |                                                                              |=====================                                                 |  30%  |                                                                              |============================                                          |  40%  |                                                                              |===================================                                   |  50%  |                                                                              |==========================================                            |  60%
#> Error in yaml::yaml.load(i): Parser error: while parsing a block mapping at line 6, column 7 did not find expected key at line 9, column 9

Created on 2021-07-16 by the reprex package (v2.0.0)

vgherard commented 3 years ago

In the first call, autotest::autotest_package(package = "kgrams"), the error occurs in autotest:::get_fn_exs(), which gets called from autotest::examples_to_yaml() with the following arguments:

library(kgrams)

package <- "kgrams"
rdname <- "preprocess"
topic <- "preprocess"
is_source <- FALSE

autotest:::get_fn_exs(package, rdname, topic, is_source)
#> Error in qstart[i]:qend[i]: Argomento NA/NaN

Created on 2021-07-16 by the reprex package (v2.0.0)

If you jump in the debugger and see how the code of the first example is preprocessed, you will notice that the output after preprocessing is invalid R code.

Hope this helps

mpadge commented 3 years ago

@vgherard Thanks for this one - this particular :bug: is definitely internal to autotest, and not to kmeans. As mentioned in #48, the entire procedure to identify input types is going to be restructured to avoid current hand-parsing of example code. The bunch of commits above partially address the bugs this revealed, but a real solution won't really be possible until the restructure. Those commits get us up to encountering the %|% symbol which indeed crashes everything here, and is unable to be resolved with autotest designed as it current is. Examples are all converted to yaml form, and parsing characters like that requires hand re-coding for each new one encountered, which is obviously not sustainable. The re-design will avoid the need for manual parsing, for which this package will provide a great test case, so thanks! I'll leave this issue open, and you'll hopefully see results here.

I'll leave this issue open, and use this package as a test cast for the re-design. Thanks!

vgherard commented 3 years ago

Thank you @mpadge, looking forward for the next version then :smiley:. If I can help in any way, let me know!

mpadge commented 2 years ago

Hi @vgherard, just letting you know that I'm finally get back to these issues, if you're still interested. I'll leave both this one and #48 open to test the new approach with once it gets that far. Sorry for any inconvenience.