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

Dynamic R code not running properly #1271

Closed
danielvartan opened this issue Nov 17, 2021 · 5 comments
Closed

Dynamic R code not running properly #1271

danielvartan opened this issue Nov 17, 2021 · 5 comments
Labels
bug an unexpected problem or unintended behavior markdown ⬇️

Comments

@danielvartan
Copy link

danielvartan commented Nov 17, 2021

Hi there!

I'm having rendering issues when using dynamic R code in a @format tag. Apparently it came up with the latest versions.

Example (see the R file here):

#'
#' @format A [`tibble`][dplyr::tibble()] with `r ncol(mctq::shift_mctq)`
#'   columns and `r nrow(mctq::shift_mctq)` rows:
#'

Rd Render:

image


devtools::session_info()
#> - Session info  --------------------------------------------------------------
#>  hash: flag: Palau, abacus, saxophone
#> 
#>  setting  value
#>  version  R version 4.1.1 (2021-08-10)
#>  os       Windows 10 x64 (build 19043)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  Portuguese_Brazil.1252
#>  ctype    Portuguese_Brazil.1252
#>  tz       America/Sao_Paulo
#>  date     2021-11-17
#>  pandoc   2.11.4 @ C:/Program Files/RStudio/bin/pandoc/ (via rmarkdown)
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version    date (UTC) lib source
#>  backports     1.3.0      2021-10-27 [1] CRAN (R 4.1.1)
#>  cachem        1.0.6      2021-08-19 [1] CRAN (R 4.1.1)
#>  callr         3.7.0      2021-04-20 [1] CRAN (R 4.1.1)
#>  cli           3.1.0.9000 2021-10-30 [1] Github (r-lib/cli@1af3d91)
#>  crayon        1.4.2      2021-10-29 [1] CRAN (R 4.1.1)
#>  desc          1.4.0      2021-09-28 [1] CRAN (R 4.1.1)
#>  devtools      2.4.2      2021-06-07 [1] CRAN (R 4.1.1)
#>  digest        0.6.28     2021-09-23 [1] CRAN (R 4.1.1)
#>  ellipsis      0.3.2      2021-04-29 [1] CRAN (R 4.1.0)
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 4.1.1)
#>  fansi         0.5.0      2021-05-25 [1] CRAN (R 4.1.1)
#>  fastmap       1.1.0      2021-01-25 [1] CRAN (R 4.1.1)
#>  fs            1.5.0      2020-07-31 [1] CRAN (R 4.1.1)
#>  glue          1.5.0      2021-11-07 [1] CRAN (R 4.1.1)
#>  highr         0.9        2021-04-16 [1] CRAN (R 4.1.1)
#>  htmltools     0.5.2      2021-08-25 [1] CRAN (R 4.1.1)
#>  knitr         1.36       2021-09-29 [1] CRAN (R 4.1.1)
#>  lifecycle     1.0.1      2021-09-24 [1] CRAN (R 4.1.1)
#>  magrittr      2.0.1      2020-11-17 [1] CRAN (R 4.1.1)
#>  memoise       2.0.0      2021-01-26 [1] CRAN (R 4.1.1)
#>  pillar        1.6.4      2021-10-18 [1] CRAN (R 4.1.1)
#>  pkgbuild      1.2.0      2020-12-15 [1] CRAN (R 4.1.1)
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.1.1)
#>  pkgload       1.2.3      2021-10-13 [1] CRAN (R 4.1.1)
#>  prettyunits   1.1.1      2020-01-24 [1] CRAN (R 4.1.1)
#>  processx      3.5.2      2021-04-30 [1] CRAN (R 4.1.1)
#>  ps            1.6.0      2021-02-28 [1] CRAN (R 4.1.1)
#>  purrr         0.3.4      2020-04-17 [1] CRAN (R 4.1.1)
#>  R.cache       0.15.0     2021-04-30 [1] CRAN (R 4.1.1)
#>  R.methodsS3   1.8.1      2020-08-26 [1] CRAN (R 4.1.1)
#>  R.oo          1.24.0     2020-08-26 [1] CRAN (R 4.1.1)
#>  R.utils       2.11.0     2021-09-26 [1] CRAN (R 4.1.1)
#>  R6            2.5.1      2021-08-19 [1] CRAN (R 4.1.1)
#>  remotes       2.4.1      2021-09-29 [1] CRAN (R 4.1.1)
#>  reprex        2.0.1      2021-08-05 [1] CRAN (R 4.1.1)
#>  rlang         0.4.12     2021-10-18 [1] CRAN (R 4.1.1)
#>  rmarkdown     2.11       2021-09-14 [1] CRAN (R 4.1.1)
#>  rprojroot     2.0.2      2020-11-15 [1] CRAN (R 4.1.1)
#>  rstudioapi    0.13       2020-11-12 [1] CRAN (R 4.1.1)
#>  sessioninfo   1.2.1      2021-11-02 [1] CRAN (R 4.1.1)
#>  stringi       1.7.5      2021-10-04 [1] CRAN (R 4.1.1)
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 4.1.1)
#>  styler        1.6.2      2021-09-23 [1] CRAN (R 4.1.1)
#>  testthat      3.1.0      2021-10-04 [1] CRAN (R 4.1.1)
#>  tibble        3.1.5      2021-09-30 [1] CRAN (R 4.1.1)
#>  usethis       2.1.3      2021-10-27 [1] CRAN (R 4.1.1)
#>  utf8          1.2.2      2021-07-24 [1] CRAN (R 4.1.1)
#>  vctrs         0.3.8      2021-04-29 [1] CRAN (R 4.1.1)
#>  withr         2.4.2      2021-04-18 [1] CRAN (R 4.1.1)
#>  xfun          0.28       2021-11-04 [1] CRAN (R 4.1.1)
#>  yaml          2.2.1      2020-02-01 [1] CRAN (R 4.1.0)
#> 
#>  [1] C:/Users/Daniel/Documents/R/win-library/4.1
#>  [2] C:/Program Files/R/R-4.1.1/library
#> 
#> ------------------------------------------------------------------------------

Created on 2021-11-17 by the reprex package (v2.0.1)

@gaborcsardi
Copy link
Member

I can't reproduce this:

❯ R -q -e 'devtools::document()'
> devtools::document()
ℹ Updating mctq documentation
ℹ Loading mctq
Writing NAMESPACE
Writing NAMESPACE
❯ grep -A 3 format man/shift_mctq.Rd
\format{
A \code{\link[dplyr:reexports]{tibble}} with 128 columns and 50 rows:

\describe{

Your session info does not include the versions of roxygen2 or the version of the package you are documenting. I used your main branch and roxygen2 7.1.2.

@danielvartan
Copy link
Author

Hi @gaborcsardi !

You couldn't reproduce because I already fixed the mctq main branch (I removed the dynamic code).

Please try using the package at this point:

https://github.com/ropensci/mctq/tree/472922d20928efc6bd1c1f5dcca0fafcd49b9e0e

I'm using roxygen2 7.1.2 too.

@gaborcsardi
Copy link
Member

gaborcsardi commented Nov 18, 2021

Got it, thanks! Simple reprex:

roxygen2:::markdown("X\n  `r (1+1)`\n")
#> [1] "X\n2)`"

It seems like a workaround is to avoid indentation:

roxygen2:::markdown("X\n`r (1+1)`\n")
#> [1] "X\n2"

@gaborcsardi gaborcsardi added bug an unexpected problem or unintended behavior markdown ⬇️ labels Nov 18, 2021
@hadley
Copy link
Member

hadley commented Apr 6, 2022

This looks like it's another bug with how commonmark records source references.

@hadley
Copy link
Member

hadley commented Jul 10, 2022

Fixed by #1391

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior markdown ⬇️
Projects
None yet
Development

No branches or pull requests

3 participants