clean_lyx: Clean up, weave or tangle Sweave files produced by LyX with...

View source: R/clean_lyx.R

clean_lyxR Documentation

Clean up, weave or tangle Sweave files produced by LyX with the SciViews Sweave module

Description

These functions process .Rnw`` files produced by LyX and the SciViews Sweave module (not the standard Sweave module provided with LyX <= 2.0.0!). The SciViews-LyX extension defines rchunk' commands to contain R chunks (embedded R code processed by Sweave). Unfortunately, LyX use to write two lines feeds for each line of code, introducing extra lines in the R chunks. Moreover, tabulations are interpreted as 8 spaces, while R code use to consider a tabulation as equivalent to 4 spaces. clean_lyx() corrects these little problems, and it should not affect R noweb files produced by a different software.

Usage

clean_lyx(RnwCon, RnwCon2 = RnwCon, encoding = "UTF-8")

cleanLyxRnw(RnwCon, RnwCon2 = RnwCon, encoding = "UTF-8")

tangle_lyx(
  file,
  driver = Rtangle(),
  syntax = getOption("SweaveSyntax"),
  encoding = "UTF-8",
  width = 80,
  useFancyQuotes = TRUE,
  annotate = TRUE,
  logFile = file.path(tempdir(), ".lyxSweave.log"),
  ...
)

tangleLyxRnw(
  file,
  driver = Rtangle(),
  syntax = getOption("SweaveSyntax"),
  encoding = "UTF-8",
  width = 80,
  useFancyQuotes = TRUE,
  annotate = TRUE,
  logFile = file.path(tempdir(), ".lyxSweave.log"),
  ...
)

purl_lyx(
  file,
  encoding = "UTF-8",
  width = 80,
  useFancyQuotes = TRUE,
  logFile = file.path(tempdir(), ".lyxSweave.log"),
  ...
)

purlLyxRnw(
  file,
  encoding = "UTF-8",
  width = 80,
  useFancyQuotes = TRUE,
  logFile = file.path(tempdir(), ".lyxSweave.log"),
  ...
)

weave_lyx(
  file,
  driver = RweaveLatex(),
  syntax = getOption("SweaveSyntax"),
  encoding = "UTF-8",
  width = 80,
  useFancyQuotes = TRUE,
  logFile = file.path(tempdir(), ".lyxSweave.log"),
  ...
)

weaveLyxRnw(
  file,
  driver = RweaveLatex(),
  syntax = getOption("SweaveSyntax"),
  encoding = "UTF-8",
  width = 80,
  useFancyQuotes = TRUE,
  logFile = file.path(tempdir(), ".lyxSweave.log"),
  ...
)

knit_lyx(
  file,
  encoding = "UTF-8",
  width = 80,
  useFancyQuotes = TRUE,
  logFile = file.path(tempdir(), ".lyxSweave.log"),
  ...
)

knitLyxRnw(
  file,
  encoding = "UTF-8",
  width = 80,
  useFancyQuotes = TRUE,
  logFile = file.path(tempdir(), ".lyxSweave.log"),
  ...
)

Arguments

RnwCon

A connection object or a character string corresponding to the path to a R noweb file to be read.

RnwCon2

Idem, but where the cleaned up R noweb file should be written (by default, on the same file or connection).

encoding

The encoding of the .Rnw file. It is UTF-8 by default, but you can change it here.

file

The Sweave source file.

driver

The actual function to do the process, see Sweave().

syntax

NULL or an object of class 'SweaveSyntax' or a character string with its name, see Sweave().

width

The width used for outputs, 80 characters by default.

useFancyQuotes

Do we use fancy quotes in R outputs?

annotate

Is the R code extracted from the .Rnw file annotated?

logFile

The file to use to log results of weaving/tangling the document.

...

Further arguments passed to the driver's setup function of Sweave() or Stangle().

Value

For clean_lyx(), a list for Sweave options found in the document; NULL for the other functions: these functions are invoked for their side effects. The function weave_lyx() uses the standard Sweave driver (but it uses knitr for LyX documents that use the SciViews Knitr module), while knit_lyx() does the same, but using the knitr driver. Similarly, purl_lyx() is the knitr counterpart of tangle_lyx() standard tangling function.

Author(s)

Philippe Grosjean

See Also

knitr::knit(), utils::Sweave()


svSweave documentation built on May 10, 2022, 5:06 p.m.