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

Templates and Markdown #594

Closed
krlmlr opened this issue Feb 19, 2017 · 3 comments
Closed

Templates and Markdown #594

krlmlr opened this issue Feb 19, 2017 · 3 comments
Labels
bug an unexpected problem or unintended behavior markdown ⬇️

Comments

@krlmlr
Copy link
Member

krlmlr commented Feb 19, 2017

Template files in man-roxygen don't seem to respect Markdown mode: krlmlr/dplyr@89b892f#commitcomment-20813612

CC @gaborcsardi.

@kevinushey
Copy link
Contributor

Reproducible example:

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

cat(
	"Roxygen: list(markdown = TRUE)",
	file = "DESCRIPTION",
	sep = "\n",
	append = TRUE
)

dir.create("man-roxygen")

cat(
	"#' @param x This is a link to [stats::rnorm()].",
	file = "man-roxygen/roxlate-rnorm.R",
	sep = "\n"
)

cat(
	"#' Foo.",
	"#'",
	"#' Description. Link: [stats::runif()]",
	"#' @template roxlate-rnorm",
	"#' @export",
	"foo <- function(x) {}",
	file = "R/foo.R",
	sep = "\n"
)

devtools::document()
writeLines(readLines("man/foo.Rd"))

This produces the file:

> writeLines(readLines("man/foo.Rd"))
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/foo.R
\name{foo}
\alias{foo}
\title{Foo.}
\usage{
foo(x)
}
\arguments{
\item{x}{This is a link to [stats::rnorm()].}
}
\description{
Description. Link: \code{\link[stats:runif]{stats::runif()}}
}

Note that the [stats::rnorm()] link was not processed, while the [stats::runif()] one was.

@jayhesselberth
Copy link

This looks to be a problem of the global md flag not being set when process_templates is called.

I can achieve the desired behavior for this example by adding a @md tag to the template.

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

cat(
  "Roxygen: list(markdown = TRUE)",
  file = "DESCRIPTION",
  sep = "\n",
  append = TRUE
)

dir.create("man-roxygen")

cat(
  "#' @md",
  "#' @param x This is a link to [stats::rnorm()].",
  file = "man-roxygen/roxlate-rnorm.R",
  sep = "\n"
)

cat(
  "#' Foo.",
  "#'",
  "#' Description. Link: [stats::runif()]",
  "#' @template roxlate-rnorm",
  "#' @export",
  "foo <- function(x) {}",
  file = "R/foo.R",
  sep = "\n"
)

devtools::document()
writeLines(readLines("man/foo.Rd"))

This writes:

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/foo.R
\name{foo}
\alias{foo}
\title{Foo.}
\usage{
foo(x)
}
\arguments{
\item{x}{This is a link to \code{\link[stats:rnorm]{stats::rnorm()}}.}
}
\description{
Description. Link: \code{\link[stats:runif]{stats::runif()}}
}

@gaborcsardi
Copy link
Member

@jayhesselberth Thanks for the digging! THis is a good workaround for now.

@hadley hadley added bug an unexpected problem or unintended behavior markdown ⬇️ labels Aug 16, 2017
@hadley hadley closed this as completed in 3f6837e Aug 17, 2017
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

5 participants