r-lib / roxygen2md

Convert elements of roxygen documentation to markdown
https://roxygen2md.r-lib.org/
67 stars 8 forks source link

roxygen2md converts Rd syntax within R code #4

Closed karawoo closed 7 years ago

karawoo commented 7 years ago

Not sure if this qualifies as a bug, but I noticed that roxygen2md converts Rd syntax that is present in R code as well as documentation. A reprex:

setwd(tempdir())
devtools::create("test")
setwd("test")

cat(
  "#' Title",
  "#' ",
  "#' @param x,y Some stuff here, and a random \\code{code tag}",
  "test_fun <- function(x, y) {",
  "paste('\\code{\', x, \'} and \', y, sep = \'\')",
  "}",
  file = "R/test_fun.R",
  sep = "\n"
)

## View function
writeLines(readLines("R/test_fun.R"))
#> #' Title
#> #' 
#> #' @param x,y Some stuff here, and a random \code{code tag}
#> test_fun <- function(x, y) {
#> paste('\code{', x, '} and ', y, sep = '')
#> }

## Convert to md and view
roxygen2md::roxygen2md()
#> Please review the changes carefully!
writeLines(readLines("R/test_fun.R"))
#> #' Title
#> #' 
#> #' @param x,y Some stuff here, and a random `code tag`
#> test_fun <- function(x, y) {
#> paste('`', x, '` and ', y, sep = '')
#> }

I would expect the \code{code tag} in the documentation to get converted, but not contents of the function. Though in fairness I was warned to review the changes carefully!

This can come up when a function in the package writes Rd style output and gets called by a \Sexpr macro, like these in ggplot2 (which is where I ran into this issue).

krlmlr commented 7 years ago

Thanks for reporting. It seems too late for ggplot2, but you could run again on HEAD~2 and double-check just to be sure.

krlmlr commented 7 years ago

Closed in 5115d65d.

github-actions[bot] commented 3 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.