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

Comments

@krlmlr
Copy link
Member

@krlmlr 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

@kevinushey kevinushey commented Mar 9, 2017

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

@jayhesselberth jayhesselberth commented Apr 29, 2017

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
Collaborator

@gaborcsardi gaborcsardi commented Apr 29, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants