# NOT RUN {
## We `dontrun` these examples as they involve pagers that should only be run
## in interactive mode
# }
# NOT RUN {
## Specify Pager parameters via list; this lets the `diff*` functions pick
## their preferred pager based on format and other output parameters, but
## allows you to modify the pager behavior.
f <- tempfile()
diffChr(1:200, 180:300, format='html', pager=list(file.path=f))
head(readLines(f)) # html output
unlink(f)
## Assuming system pager is `less` and terminal supports ANSI ESC sequences
## Equivalent to running `less -RFX`
diffChr(1:200, 180:300, pager=PagerSystemLess(flags="RFX"))
## If the auto-selected pager would be the system pager, we could
## equivalently use:
diffChr(1:200, 180:300, pager=list(flags="RFX"))
## System pager is not less, but it supports ANSI escape sequences
diffChr(1:200, 180:300, pager=PagerSystem(ansi=TRUE))
## Use a custom pager, in this case we make up a trivial one and configure it
## always page (`threshold=0L`)
page.fun <- function(x) cat(paste0("| ", readLines(x)), sep="\n")
page.conf <- PagerSystem(pager=page.fun, threshold=0L)
diffChr(1:200, 180:300, pager=page.conf, disp.width=getOption("width") - 2)
## Set-up the custom pager as the default pager
options(diffobj.pager=page.conf)
diffChr(1:200, 180:300)
## A blocking pager (this is effectively very similar to what `PagerBrowser`
## does); need to block b/c otherwise temp file with diff could be deleted
## before the device has a chance to read it since `browseURL` is not
## blocking itself. On OS X we need to specify the extension so the correct
## program opens it (in this case `TextEdit`):
page.conf <- Pager(pager=browseURL, file.ext="txt", make.blocking=TRUE)
diffChr(1:200, 180:300, pager=page.conf, format='raw')
## An alternative to a blocking pager is to disable the
## auto-file deletion; here we also specify a file location
## explicitly so we can recover the diff text.
f <- paste0(tempfile(), ".html") # must specify .html
diffChr(1:5, 2:6, format='html', pager=list(file.path=f))
tail(readLines(f))
unlink(f)
# }
Run the code above in your browser using DataLab