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

Indentation ignored in @examples section #27

Closed
backlin opened this issue Aug 9, 2011 · 6 comments
Closed

Indentation ignored in @examples section #27

backlin opened this issue Aug 9, 2011 · 6 comments
Labels

Comments

@backlin
Copy link

@backlin backlin commented Aug 9, 2011

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
Copy link

@mlt mlt commented Aug 24, 2011

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

@hadley
Copy link
Member

@hadley hadley commented Aug 25, 2011

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

@mlt
Copy link

@mlt mlt commented Aug 25, 2011

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
Copy link
Member

@hadley hadley commented Aug 25, 2011

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
Copy link

@mlt mlt commented Aug 25, 2011

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

@mlt
Copy link

@mlt mlt commented Aug 25, 2011

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 Oct 25, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants