Skip to content

Commit

Permalink
split long lines in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
daroczig committed May 27, 2013
1 parent b43ddd3 commit 59b1e5a
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 63 deletions.
22 changes: 16 additions & 6 deletions R/brew.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
#' \item John MacFarlane (2012): _Pandoc User's Guide_. \url{http://johnmacfarlane.net/pandoc/README.html}
#' }
#' @examples \dontrun{
#' text <- paste('# Header', '', 'What a lovely list:\n<%=as.list(runif(10))%>', 'A wide table:\n<%=mtcars[1:3, ]%>', 'And a nice chart:\n\n<%=plot(1:10)%>', sep = '\n')
#' text <- paste('# Header', '',
#' 'What a lovely list:\n<%=as.list(runif(10))%>',
#' 'A wide table:\n<%=mtcars[1:3, ]%>',
#' 'And a nice chart:\n\n<%=plot(1:10)%>', sep = '\n')
#' Pandoc.brew(text = text)
#' Pandoc.brew(text = text, output = tempfile(), convert = 'html')
#' Pandoc.brew(text = text, output = tempfile(), convert = 'pdf')
Expand All @@ -38,14 +41,21 @@
#'
#' ## package bundled examples
#' Pandoc.brew(system.file('examples/minimal.brew', package='pander'))
#' Pandoc.brew(system.file('examples/minimal.brew', package='pander'), output = tempfile(), convert = 'html')
#' Pandoc.brew(system.file('examples/minimal.brew', package='pander'),
#' output = tempfile(), convert = 'html')
#' Pandoc.brew(system.file('examples/short-code-long-report.brew', package='pander'))
#' Pandoc.brew(system.file('examples/short-code-long-report.brew', package='pander'), output = tempfile(), convert = 'html')
#' Pandoc.brew(system.file('examples/short-code-long-report.brew', package='pander'),
#' output = tempfile(), convert = 'html')
#'
#' ## brew returning R objects
#' str(Pandoc.brew(text='Pi equals to <%=pi%>.\nAnd here are some random data:\n<%=runif(10)%>'))
#' str(Pandoc.brew(text='# Header <%=1%>\nPi is <%=pi%> which is smaller then <%=2%>.\nfoo\nbar\n <%=3%>\n<%=mtcars[1:2,]%>'))
#' str(Pandoc.brew(text='<%for (i in 1:5) {%>\n Pi has a lot (<%=i%>) of power: <%=pi^i%><%}%>'))
#' str(Pandoc.brew(text='Pi equals to <%=pi%>.
#' And here are some random data:\n<%=runif(10)%>'))
#'
#' str(Pandoc.brew(text='# Header <%=1%>\nPi is <%=pi%> which is smaller then <%=2%>.
#' foo\nbar\n <%=3%>\n<%=mtcars[1:2,]%>'))
#'
#' str(Pandoc.brew(text='<%for (i in 1:5) {%>
#' Pi has a lot (<%=i%>) of power: <%=pi^i%><%}%>'))
#' }
Pandoc.brew <- function(file = stdin(), output = stdout(), convert = FALSE, open = TRUE, graph.name, graph.dir, graph.hi.res = FALSE, text = NULL, envir = parent.frame()) {

Expand Down
5 changes: 4 additions & 1 deletion R/convert.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ openFileInOS <- function(f) {
#' @examples \dontrun{
#' Pandoc.convert(text = c('# Demo', 'with a paragraph'))
#' Pandoc.convert('http://rapporter.github.com/pander/minimal.md')
#' ## Note: the generated HTML is not showing images with relative path from the above file. Based on that `pdf`, `docx` etc. formats would not work! If you want to convert an online markdown file to other formats with this function, please pre-process the file to have absolute paths instead.
#' ## Note: the generated HTML is not showing images with relative path from the above file.
#' ## Based on that `pdf`, `docx` etc. formats would not work! If you want to convert an
#' ## online markdown file to other formats with this function, please pre-process the file
#' ## to have absolute paths instead.
#' }
Pandoc.convert <- function(f, text, format = 'html', open = TRUE, options = '', footer = TRUE, proc.time, portable.html = TRUE) {

Expand Down
56 changes: 35 additions & 21 deletions R/evals.R
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ eval.msgs <- function(src, env = NULL, showInvisible = FALSE, graph.unify = eval
#' 'ggplot(mtcars) + geom_point(aes(x = hp, y = mpg))')
#' evals(txt)
#'
#' ## the same commands in one string but also evaluating the `plot` with `text` (note the leading "+" on the beginning of `text...` line)
#' ## the same commands in one string but also evaluating the `plot` with `text`
#' ## (note the leading "+" on the beginning of `text...` line)
#' txt <- 'df <- mtcars
#' plot(mtcars$hp, pch = 19)
#' +text(mtcars$hp, label = rownames(mtcars), pos = 4)
Expand All @@ -462,51 +463,58 @@ eval.msgs <- function(src, env = NULL, showInvisible = FALSE, graph.unify = eval
#'
#' ## adding a caption to a plot
#' evals('set.caption("FOO"); plot(1:10)')
#' ## `plot` is started with a `+` to eval the codes in the same chunk (no extra chunk with NULL result)
#' ## `plot` is started with a `+` to eval the codes in the same chunk
#' ## (no extra chunk with NULL result)
#' evals('set.caption("FOO"); +plot(1:10)')
#'
#' ## handling warnings
#' evals('chisq.test(mtcars$gear, mtcars$hp)')
#' evals(list(c('chisq.test(mtcars$gear, mtcars$am)', 'pi', 'chisq.test(mtcars$gear, mtcars$hp)')), parse = F)
#' evals(c('chisq.test(mtcars$gear, mtcars$am)', 'pi', 'chisq.test(mtcars$gear, mtcars$hp)'))
#' evals(list(c('chisq.test(mtcars$gear, mtcars$am)', 'pi',
#' 'chisq.test(mtcars$gear, mtcars$hp)')), parse = FALSE)
#' evals(c('chisq.test(mtcars$gear, mtcars$am)',
#' 'pi',
#' 'chisq.test(mtcars$gear, mtcars$hp)'))
#'
#' ## handling errors
#' evals('runiff(20)')
#' evals('Old MacDonald had a farm\\dots')
#' evals('## Some comment')
#' evals(c('runiff(20)', 'Old MacDonald had a farm?'))
#' evals(list(c('runiff(20)', 'Old MacDonald had a farm?')), parse = F)
#' evals(list(c('runiff(20)', 'Old MacDonald had a farm?')), parse = FALSE)
#' evals(c('mean(1:10)', 'no.R.function()'))
#' evals(list(c('mean(1:10)', 'no.R.function()')), parse = F)
#' evals(list(c('mean(1:10)', 'no.R.function()')), parse = FALSE)
#' evals(c('no.R.object', 'no.R.function()', 'very.mixed.up(stuff)'))
#' evals(list(c('no.R.object', 'no.R.function()', 'very.mixed.up(stuff)')), parse = F)
#' evals(list(c('no.R.object', 'no.R.function()', 'very.mixed.up(stuff)')), parse = FALSE)
#' evals(c('no.R.object', 'Old MacDonald had a farm\\dots', 'pi'))
#' evals('no.R.object;Old MacDonald had a farm\\dots;pi', parse = F)
#' evals(list(c('no.R.object', 'Old MacDonald had a farm\\dots', 'pi')), parse = F)
#' evals('no.R.object;Old MacDonald had a farm\\dots;pi', parse = FALSE)
#' evals(list(c('no.R.object', 'Old MacDonald had a farm\\dots', 'pi')), parse = FALSE)
#'
#' ## graph options
#' evals('plot(1:10)')
#' evals('plot(1:10);plot(2:20)')
#' evals('plot(1:10)', graph.output = 'jpg')
#' evals('plot(1:10)', height = 800)
#' evals('plot(1:10)', height = 800, hi.res = T)
#' evals('plot(1:10)', graph.output = 'pdf', hi.res = T)
#' evals('plot(1:10)', height = 800, hi.res = TRUE)
#' evals('plot(1:10)', graph.output = 'pdf', hi.res = TRUE)
#' evals('plot(1:10)', res = 30)
#' evals('plot(1:10)', graph.name = 'myplot')
#' evals(list('plot(1:10)', 'plot(2:20)'), graph.name = 'myplots-%d')
#' evals('plot(1:10)', graph.env = TRUE)
#' evals('x <- runif(100);plot(x)', graph.env = TRUE)
#' evals(c('plot(1:10)', 'plot(2:20)'), graph.env = TRUE)
#' evals(c('x <- runif(100)', 'plot(x)','y <- runif(100)', 'plot(y)'), graph.env = TRUE)
#' evals(list(c('x <- runif(100)', 'plot(x)'), c('y <- runif(100)', 'plot(y)')), graph.env = TRUE, parse = F)
#' evals(list(
#' c('x <- runif(100)', 'plot(x)'),
#' c('y <- runif(100)', 'plot(y)')),
#' graph.env = TRUE, parse = FALSE)
#' evals('plot(1:10)', graph.recordplot = TRUE)
#' ## unprinted lattice plot
#' evals('histogram(mtcars$hp)', graph.recordplot = TRUE)
#'
#' ## caching
#' system.time(evals('plot(mtcars)'))
#' system.time(evals('plot(mtcars)')) # running again to see the speed-up :)
#' system.time(evals('plot(mtcars)', cache = FALSE)) # cache disabled
#' system.time(evals('plot(mtcars)')) # running again to see the speed-up :)
#' system.time(evals('plot(mtcars)', cache = FALSE)) # cache disabled
#'
#' ## caching mechanism does check what's inside a variable:
#' x <- mtcars
Expand All @@ -517,12 +525,13 @@ eval.msgs <- function(src, env = NULL, showInvisible = FALSE, graph.unify = eval
#' system.time(evals('plot(x)'))
#'
#' ## stress your CPU - only once!
#' evals('x <- sapply(rep(mtcars$hp, 1e3), mean)') # run it again!
#' evals('x <- sapply(rep(mtcars$hp, 1e3), mean)') # run it again!
#'
#' ## play with cache
#' require(lattice)
#' evals('histogram(rep(mtcars$hp, 1e5))')
#' ## nor run the below call - which would return the cached version of the above call :)
#' ## nor run the below call
#' ## that would return the cached version of the above call :)
#' f <- histogram
#' g <- rep
#' A <- mtcars$hp
Expand Down Expand Up @@ -552,9 +561,11 @@ eval.msgs <- function(src, env = NULL, showInvisible = FALSE, graph.unify = eval
#' evals('matrix(runif(25), 5, 5)', hooks = list('matrix' = round))
#'
#' ## setting default hook
#' evals(c('runif(10)', 'matrix(runif(9), 3, 3)'), hooks = list('default'=round))
#' evals(c('runif(10)', 'matrix(runif(9), 3, 3)'),
#' hooks = list('default'=round))
#' ## round all values except for matrices
#' evals(c('runif(10)', 'matrix(runif(9), 3, 3)'), hooks = list(matrix = 'print', 'default' = round))
#' evals(c('runif(10)', 'matrix(runif(9), 3, 3)'),
#' hooks = list(matrix = 'print', 'default' = round))
#'
#' # advanced hooks
#' hooks <- list('numeric' = list(round, 2), 'matrix' = list(round, 1))
Expand All @@ -572,11 +583,14 @@ eval.msgs <- function(src, env = NULL, showInvisible = FALSE, graph.unify = eval
#' # note the following will not be filtered!
#' evals('matrix(1,1,1)', length = 1)
#'
#' # if you do not want to let such things be eval-ed in the middle of a string use it with other filters :)
#' # if you do not want to let such things be eval-ed in the middle of a string
#' # use it with other filters :)
#' evals('matrix(1,1,1)', length = 1, classes = 'numeric')
#'
#'# hooks & filtering
#' evals('matrix(5,5,5)', hooks = list('matrix' = pander.return), output = 'result')
#' # hooks & filtering
#' evals('matrix(5,5,5)',
#' hooks = list('matrix' = pander.return),
#' output = 'result')
#'
#' # eval-ing chunks in given environment
#' myenv <- new.env()
Expand Down
15 changes: 11 additions & 4 deletions R/pandoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,10 @@ pandoc.title <- function(...)
#' pandoc.list(letters[1:5], loose = TRUE)
#'
#' ## nested lists
#' l <- list("First list element", rep.int('sub element', 5), "Second element", list('F', 'B', 'I', c('phone', 'pad', 'talics')))
#' l <- list("First list element",
#' rep.int('sub element', 5),
#' "Second element",
#' list('F', 'B', 'I', c('phone', 'pad', 'talics')))
#' pandoc.list(l)
#' pandoc.list(l, loose = TRUE)
#' pandoc.list(l, 'roman')
Expand Down Expand Up @@ -474,7 +477,9 @@ pandoc.list <- function(...)
#' pandoc.table(table(state.division, state.region))
#' pandoc.table(table(state.division, state.region), justify = 'centre')
#'
#' m <- data.frame(a=c(1, -500, 10320, 23, 77), b=runif(5), c=c('a', 'bb', 'ccc', 'dddd', 'eeeee'))
#' m <- data.frame(a = c(1, -500, 10320, 23, 77),
#' b = runif(5),
#' c = c('a', 'bb', 'ccc', 'dddd', 'eeeee'))
#' pandoc.table(m)
#' pandoc.table(m, justify = c('right', 'left', 'centre'))
#'
Expand All @@ -483,7 +488,8 @@ pandoc.list <- function(...)
#' pandoc.table(mtcars, caption = 'Only once after the first part!')
#'
#' ## tables with line breaks in cells
#' ## Note: line breaks are removed from table content and added automatically based on "split.cells" parameter!
#' ## NOTE: line breaks are removed from table content
#' ## and added automatically based on "split.cells" parameter!
#' t <- data.frame(a = c('hundreds\nof\nmouses', '3 cats'), b=c('FOO is nice', 'BAR\nBAR2'))
#' pandoc.table(t)
#' pandoc.table(t, split.cells = 5)
Expand All @@ -495,7 +501,8 @@ pandoc.list <- function(...)
#' pandoc.table(t, style = "grid")
#' pandoc.table(t, style = "grid", split.cells = 5)
#' pandoc.table(t, style = "simple")
#' tryCatch(pandoc.table(t, style = "simple", split.cells = 5), error = function(e) 'Yeah, no newline support in simple tables')
#' tryCatch(pandoc.table(t, style = "simple", split.cells = 5),
#' error = function(e) 'Yeah, no newline support in simple tables')
#' pandoc.table(t, style = "rmarkdown")
#'
#' ## highlight cells
Expand Down
22 changes: 16 additions & 6 deletions man/Pandoc.brew.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@
}
\examples{
\dontrun{
text <- paste('# Header', '', 'What a lovely list:\\n<\%=as.list(runif(10))\%>', 'A wide table:\\n<\%=mtcars[1:3, ]\%>', 'And a nice chart:\\n\\n<\%=plot(1:10)\%>', sep = '\\n')
text <- paste('# Header', '',
'What a lovely list:\\n<\%=as.list(runif(10))\%>',
'A wide table:\\n<\%=mtcars[1:3, ]\%>',
'And a nice chart:\\n\\n<\%=plot(1:10)\%>', sep = '\\n')
Pandoc.brew(text = text)
Pandoc.brew(text = text, output = tempfile(), convert = 'html')
Pandoc.brew(text = text, output = tempfile(), convert = 'pdf')
Expand All @@ -94,14 +97,21 @@ Pandoc.brew(text='<\%for (i in 1:5) {\%>\\n Pi has a lot (<\%=i\%>) of power: <\

## package bundled examples
Pandoc.brew(system.file('examples/minimal.brew', package='pander'))
Pandoc.brew(system.file('examples/minimal.brew', package='pander'), output = tempfile(), convert = 'html')
Pandoc.brew(system.file('examples/minimal.brew', package='pander'),
output = tempfile(), convert = 'html')
Pandoc.brew(system.file('examples/short-code-long-report.brew', package='pander'))
Pandoc.brew(system.file('examples/short-code-long-report.brew', package='pander'), output = tempfile(), convert = 'html')
Pandoc.brew(system.file('examples/short-code-long-report.brew', package='pander'),
output = tempfile(), convert = 'html')

## brew returning R objects
str(Pandoc.brew(text='Pi equals to <\%=pi\%>.\\nAnd here are some random data:\\n<\%=runif(10)\%>'))
str(Pandoc.brew(text='# Header <\%=1\%>\\nPi is <\%=pi\%> which is smaller then <\%=2\%>.\\nfoo\\nbar\\n <\%=3\%>\\n<\%=mtcars[1:2,]\%>'))
str(Pandoc.brew(text='<\%for (i in 1:5) {\%>\\n Pi has a lot (<\%=i\%>) of power: <\%=pi^i\%><\%}\%>'))
str(Pandoc.brew(text='Pi equals to <\%=pi\%>.
And here are some random data:\\n<\%=runif(10)\%>'))

str(Pandoc.brew(text='# Header <\%=1\%>\\nPi is <\%=pi\%> which is smaller then <\%=2\%>.
foo\\nbar\\n <\%=3\%>\\n<\%=mtcars[1:2,]\%>'))

str(Pandoc.brew(text='<\%for (i in 1:5) {\%>
Pi has a lot (<\%=i\%>) of power: <\%=pi^i\%><\%}\%>'))
}
}
\references{
Expand Down
5 changes: 4 additions & 1 deletion man/Pandoc.convert.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
\dontrun{
Pandoc.convert(text = c('# Demo', 'with a paragraph'))
Pandoc.convert('http://rapporter.github.com/pander/minimal.md')
## Note: the generated HTML is not showing images with relative path from the above file. Based on that `pdf`, `docx` etc. formats would not work! If you want to convert an online markdown file to other formats with this function, please pre-process the file to have absolute paths instead.
## Note: the generated HTML is not showing images with relative path from the above file.
## Based on that `pdf`, `docx` etc. formats would not work! If you want to convert an
## online markdown file to other formats with this function, please pre-process the file
## to have absolute paths instead.
}
}
\references{
Expand Down
Loading

0 comments on commit 59b1e5a

Please sign in to comment.