Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Indentation ignored in @examples section #27

Closed
backlin opened this Issue · 6 comments

3 participants

@backlin

This bug is described at in this StackOverflow question and exists both in the roxygen and roxygen2 packages.

A demonstratation can be downloaded from here.

@mlt

I also miss this feature. Heavy use of lattice looks unreadable in example :(.

@hadley
Collaborator

A contributed test case would make this bug more likely to get fixed quickly...

@mlt

Here is the function snippet

##' Plots periodogram
##'
##' <details>
##' @title Periodogram plot
##' @param s
##' @return trellis object
##' @author Mikhail Titov
##' @examples
##' x <- EuStockMarkets[,"FTSE"]
##' a <- start(EuStockMarkets)
##' b <- end(EuStockMarkets)
##' ti <- seq(ISOdate(a[1],1,1)+a[2]*86400,
##'           ISOdate(b[1],1,1)+b[2]*86400,
##'           length.out=length(x))         # something is not quite right here but who cares
##' s <- spec.ls(as.numeric(ti)/86400, x, plot=FALSE)
##' bins <- cut(s)
##' conf.lim <- ci.spec(s)
##' conf.y <- max(s$spec)/conf.lim[2]
##' lm1 <- lm(10*log10(psd)~log10(period), bins)
##' psd.fig <- plot(s) +
##'     layer({
##'         panel.lines(rep(max(s$freq), 2), 10*log10(conf.y*conf.lim), col="blue")
##'         panel.abline(lm1)
##'         panel.xyplot(log10(out$period), 10*log10(out$psd), col="red")
##'         at <- log10(out[2,])
##'         panel.text(at$period, 10*at$psd,
##'                    substitute(Delta == d, list(d=coef(lm1)[2]/10)), adj=c(0.5,-8))
##'     })
##' plot(psd.fig)
plot.spec <- function(s) {
    dat <- data.frame(period=1/s$freq, dB=log10(s$spec)*10)
    xyplot(dB~period, dat, type='l',
           scales=list(x=list(log=10)),
           xscale.components=xscale.components.log10ticks,
           panel=function(x,y,...) {
               panel.grid.log(y=FALSE)
               panel.xyplot(x,y,...)
           }
           , ylab="Spectrum, dB", xlab="Period, days"
           )
}
@hadley
Collaborator

I was thinking more along the lines of a test case such as https://github.com/klutometis/roxygen/blob/master/inst/tests/test-had.R ...

@mlt

Oh... I didn't know about testthat package. However I can't find where fixed comes from :(

@mlt

I guess it should be something like the following.

library(testthat)
library(roxygen2)

context("Rd")
roc <- rd_roclet()

get_tag <- roxygen2:::get_tag

test_that("@examples captures examples", {
    out <- roc_proc_text(roc, "
#' @name a
#' @examples a <-
#'     2
NULL")[[1]]

    examples <- get_tag(out, "examples")$values
    expect_match(examples, fixed("a <-\n    2"), all = FALSE)
})

Once again I'm not quite sure what is fixed so I can't test it.
P.S. How to make ess to correctly indent multiline strings? It thinks that it is a comment or something and doesn't indent lines starting with # properly:(It was a lame question:)

@hadley hadley closed this in 5973ef2
@yihui yihui referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.