[Sciviews-commits] r504 - komodo/SciViews-K/udl pkg/svSweave pkg/svSweave/R pkg/svSweave/man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jan 2 12:34:43 CET 2013


Author: phgrosjean
Date: 2013-01-02 12:34:43 +0100 (Wed, 02 Jan 2013)
New Revision: 504

Added:
   pkg/svSweave/man/Rdoc.Rd
Modified:
   komodo/SciViews-K/udl/Rlex.udl
   komodo/SciViews-K/udl/wiki2R.udl
   pkg/svSweave/DESCRIPTION
   pkg/svSweave/NAMESPACE
   pkg/svSweave/NEWS
   pkg/svSweave/R/asciidoc.R
   pkg/svSweave/R/svSweave-internal.R
   pkg/svSweave/R/tangleLyxRnw.R
   pkg/svSweave/R/weaveLyxRnw.R
   pkg/svSweave/man/asciidoc.Rd
   pkg/svSweave/man/cleanLyxRnw.Rd
   pkg/svSweave/man/svSweave-package.Rd
Log:
Further work in Asciidoc format support in svSweave and Rwiki syntax highlighter in SciViews-K

Modified: komodo/SciViews-K/udl/Rlex.udl
===================================================================
--- komodo/SciViews-K/udl/Rlex.udl	2013-01-01 21:09:34 UTC (rev 503)
+++ komodo/SciViews-K/udl/Rlex.udl	2013-01-02 11:34:43 UTC (rev 504)
@@ -2666,9 +2666,9 @@
 # assignations with '='). That is: arg/var = (but not var ==)
 /[$NMSTART](?=[$CS]*[$WS]*\=[^\=])/ : paint(upto, SSL_DEFAULT), => IN_SSL_ARGUMENT
 
-# Special case of SciViews::R("Main title") where we want to colorize
-# Main title as a R wiki M_PI element
-"SciViews::R" : paint(upto, SSL_DEFAULT), paint(include, SSL_REGEX), => IN_SSL_DOCHEADER
+# Special case of svSweave::Rdoc("Main title") or Rdoc("Main title")
+# where we want to colorize main title as a Rdoc M_PI element
+"svSweave::Rdoc" : paint(upto, SSL_DEFAULT), paint(include, SSL_REGEX), => IN_SSL_DOCHEADER
 
 # SSL_VARIABLE also colorizes namespaces ns in ns::fun() or ns:::fun()
 # So the SSL_VARIABLE style highlight essentially various pieces of

Modified: komodo/SciViews-K/udl/wiki2R.udl
===================================================================
--- komodo/SciViews-K/udl/wiki2R.udl	2013-01-01 21:09:34 UTC (rev 503)
+++ komodo/SciViews-K/udl/wiki2R.udl	2013-01-02 11:34:43 UTC (rev 504)
@@ -31,12 +31,12 @@
 #
 # ***** END LICENSE BLOCK *****
 
-# Wiki components are switch back to R using !" again at the beginning of a line
+# Wiki chunks are switch back to R using !<<...>>=" at the beginning of a line
 
 family markup
 
 state in_wiki_default_start_of_line:
-/[!]"/ : paint(upto, M_CDATA), paint(include, M_TAGNAME), => IN_M_WIKI_STOP
+/[!]<<.*>>="/ : paint(upto, M_CDATA), paint(include, M_TAGNAME), => IN_M_WIKI_STOP
 
 state IN_M_WIKI_STOP:
 /^/ : paint(upto, M_CDATA), => IN_SSL_DEFAULT

Modified: pkg/svSweave/DESCRIPTION
===================================================================
--- pkg/svSweave/DESCRIPTION	2013-01-01 21:09:34 UTC (rev 503)
+++ pkg/svSweave/DESCRIPTION	2013-01-02 11:34:43 UTC (rev 504)
@@ -1,7 +1,7 @@
 Package: svSweave
 Type: Package
-Version: 0.9-5
-Date: 2012-08-15
+Version: 0.9-6
+Date: 2013-01-02
 Title: SciViews GUI API - Sweave functions
 Authors at R: c(person("Philippe", "Grosjean", role = c("aut", "cre"),
   email = "phgrosjean at sciviews.org"))

Modified: pkg/svSweave/NAMESPACE
===================================================================
--- pkg/svSweave/NAMESPACE	2013-01-01 21:09:34 UTC (rev 503)
+++ pkg/svSweave/NAMESPACE	2013-01-02 11:34:43 UTC (rev 504)
@@ -5,7 +5,8 @@
        purlLyxRnw,
        tangleLyxRnw,
        weaveLyxRnw,
-       RasciidocToRnw,
-       RasciidocConvert,
-       RasciidocThemes,
-       svBuild)
+       Rdoc,
+       RdocToRnw,
+       RdocConvert,
+       RdocThemes,
+       makeRdoc)

Modified: pkg/svSweave/NEWS
===================================================================
--- pkg/svSweave/NEWS	2013-01-01 21:09:34 UTC (rev 503)
+++ pkg/svSweave/NEWS	2013-01-02 11:34:43 UTC (rev 504)
@@ -1,5 +1,13 @@
 = svSweave News
 
+== Changes in svSweave 0.9-6
+
+* Slight reworking of the Asciidoc-related function RdocXXX(). svBuild() is
+  renamed makeRdoc() to be more explicit.
+
+* Addition of Rdoc() function that creates an Asciidoc header.
+
+
 == Changes in svSweave 0.9-5
 
 * Now knitr can also be used to weave your documents (knitLyxRnw/purlLyxRnw).

Modified: pkg/svSweave/R/asciidoc.R
===================================================================
--- pkg/svSweave/R/asciidoc.R	2013-01-01 21:09:34 UTC (rev 503)
+++ pkg/svSweave/R/asciidoc.R	2013-01-02 11:34:43 UTC (rev 504)
@@ -1,39 +1,154 @@
-## Routines to manage and convert SciViews R script to asciidoc-sweave
+## Routines to manage and convert SciViews Rdoc to asciidoc-sweave
 ## Copyright (c) 2012, Ph. Grosjean (phgrosjean at sciviews.org)
 ## Note: !"doc block" is managed by the SciViews version of `!`,
 ## otherwise it produces an error... So, you have to place require(SciViews)
-## in the initialisation block (second line) of the SciViews R script!
+## in the initialisation block (second line) of the SciViews Rdoc!
 
-RasciidocToRnw <- function (Rfile, RnwFile, encoding)
+Rdoc <- function (title, author, email, revnumber = NULL, revdate = NULL,
+revremark = NULL, copyright = "cc-by", encoding = "utf-8", lang = "en",
+pagetitle = NULL, description = "SciViews Rdoc", keywords = NULL,
+format = "html", theme = "SciViews", max.width = 720, width = "100%",
+toc = c("top", "side", "manual", "none"), toc.title = NULL, toclevels = 3,
+numbered = TRUE, data.uri = TRUE, frame = "topbot", grid = "rows",
+align = "center", halign = "center", pygments = FALSE, slidefontsizeadjust = 0,
+SweaveOpts = list(prefix.string = "figures/fig", width = 7.2, height = 7.2, pdf = TRUE),
+SweaveInit = { options(width = 90); options(SweaveHooks = list(fig = function()
+par(col.lab = "#434366", col.main = "#434366")))}
+)
 {
-	## Converts a SciViews R script into an sweave document (.Rnw)
+	## Format AsciiDocsciidoc attributes
+	asciiAttr <- function (header = NULL, name, value) {
+		if (!length(value)) return(header)
+		paste0(header, ":", name, ": ", paste(value, collapse = ","), "\n")
+	}
 	
-	## If Rfile is missing, try to get it from option or the command line
-	if (missing(Rfile)) Rfile <- .Rfile()
+	## Title must be a single string
+	title <- as.character(title)[1]
+	if (!length(title))
+		stop("You must provide a title for your Rdoc")
 	
+	## Idem for author, but allow several names
+	## TODO: Allows for first middle last and must replace space inside items by _
+	author <- paste(author, collapse = ", ")
+	if (!length(author))
+		stop("You must provide at least one author for your Rdoc")
+	
+	## Check email
+	email <- as.character(email)[1]
+	if (!length(email) || !grepl("^.+ at .+$", email))
+		stop("You must provide a correct email address for your Rdoc")
+	
+	## Compute revision field: [revnumber], [revdate]:\n[revremark]
+	if (length(revnumber))
+		revfield <- paste0(revfield, ", ") else revfield <- ""
+	if (!length(revdate)) revdate <- format(Sys.Date(), format = "%B %Y")
+	revfield <- paste0(revfield, revdate)
+	if (length(revremark))
+		revfield <- paste0(revfield, ":\n", paste(revremark, collapse = "\n"))
+		
+	## Create the Asciidoc header
+	header <- paste0("!\"\n",
+		"= ", title, "\n",
+		author, " <", email, ">\n",
+		revfield, "\n"
+	)
+	
+	## Rework copyright
+	if (length(copyright)) {
+		if (!grepl("^[^,]+,[^,]+,[ \t]*[0-9]{4}$", copyright)) {
+			year <- substring(revdate, nchar(revdate) - 3)
+			copyright <- paste0(copyright, ", ", author, ", ", year)
+		}
+		header <- asciiAttr(header, "copyright", copyright)
+	}
+	
+	## Add more attributes
+	header <- asciiAttr(header, "encoding", encoding)
+	header <- asciiAttr(header, "lang", lang)
+	header <- asciiAttr(header, "title", pagetitle)
+	header <- asciiAttr(header, "description", description)
+	header <- asciiAttr(header, "keywords", keywords)
+	header <- asciiAttr(header, "format", format)
+	header <- asciiAttr(header, "theme", theme)
+	header <- asciiAttr(header, "max-width", max.width)
+	header <- asciiAttr(header, "width", width)
+	
+	## How to format the toc?
+	toc <- switch(as.character(toc)[1],
+		top = ":toc:\n",
+		side = ":toc2:\n",
+		manual = ":toc:\n:toc-placement: manual\n",
+		none = ":toc!:\n",
+		stop("'toc' must be 'top', 'side', 'manual' or ''none'"))
+	header <- paste0(header, toc)
+	header <- asciiAttr(header, "toc-title", toc.title)
+	header <- asciiAttr(header, "toclevels", toclevels)
+	if (isTRUE(numbered)) header <- paste0(header, ":numbered:\n")
+	if (isTRUE(data.uri)) header <- paste0(header, ":data-uri:\n")
+	header <- asciiAttr(header, "frame", frame)
+	header <- asciiAttr(header, "grid", grid)
+	header <- asciiAttr(header, "align", align)
+	header <- asciiAttr(header, "halign", halign)
+	if (isTRUE(pygments)) header <- paste0(header, ":pygments:\n")
+	header <- asciiAttr(header, "slidefontsizeadjust", slidefontsizeadjust)
+	
+	## Rework SweaveOpts
+	if (length(SweaveOpts)) {
+		if (!is.list(SweaveOpts))
+			stop("'SweaveOpts' must be a named list or NULL")
+		SweaveOpts <- paste(names(SweaveOpts), SweaveOpts, sep = " = ",
+			collapse = ", ")
+		header <- paste0(header,
+			"\n//////////\n",
+			"\\SweaveOpts{", SweaveOpts, "}\n",
+			"//////////\n"				 
+		)
+	} else header <- paste0(header, "\n") # End of header section
+		
+	## Add SweaveInit chunk here... or !<<>>="
+	## TODO: allow for either require(SciViews), or a def of `!`
+	if (is.null(SweaveInit)) SweaveInit <- "" else
+		SweaveInit <- paste(deparse(substitute(SweaveInit)), collapse = "\n")
+	header <- paste0(header,
+		"!<<init, echo = FALSE, results = hide>>=\"\n",
+		"## SweaveInit code\n",
+		SweaveInit,
+		"\n## More initialization\n",
+		"require(\"SciViews\")\n"
+	)
+	invisible(header)
+}
+
+RdocToRnw <- function (RdocFile, RnwFile, encoding)
+{
+	## Converts a SciViews Rdoc into an sweave document (.Rnw)
+	
+	## If RdocFile is missing, try to get it from option or the command line
+	if (missing(RdocFile)) RdocFile <- .RdocFile()
+	
 	## Get RnwFile
-	if (missing(RnwFile)) RnwFile <- getOption("sv.RnwFile",
-		.fileExt(Rfile, "Rnw"))
+	if (missing(RnwFile)) RnwFile <- getOption("Rnw.file",
+		.fileExt(RdocFile, "Rnw"))
 	## Make sure it is not an old file at the end of the process that remains
 	unlink(RnwFile)
 
 	## Get encoding
-	if (missing(encoding)) encoding <- getOption("sv.encoding", "UTF-8")
+	if (missing(encoding)) encoding <- getOption("Rdoc.encoding", "UTF-8")
 		
-	## Read Rfile content
-	Rscript <- readLines(Rfile, encoding = encoding)
+	## Read RdocFile content
+	Rscript <- readLines(RdocFile, encoding = encoding)
 	l <- length(Rscript)
 	
-	## Detect doc chunks
-	start <- grepl('^!"@[ \t]*$', Rscript)
+	## Detect doc chunks (start with !", and end with !<<...>>=")
+	start <- grepl('^!"[ \t]*$', Rscript)
 	end <- grepl('^<<.*>>="[ \t]*$', Rscript)
 	## Must have at least one doc chunk and same number of starts and ends
 	nstart <- sum(start)
 	nend <- sum(end)
 	if (nstart < 1)
-		stop("Incorrect SciViews R script (it must contain at least one doc chunk)")
+		stop("Incorrect SciViews Rdoc (it must contain at least one doc chunk)")
 	if (sum(end) != nstart)
-		stop("Incorrect SciViews R script (", nstart, " doc chunk starts but ",
+		stop("Incorrect SciViews Rdoc (", nstart, " doc chunk starts but ",
 			nend, " ends)")
 	## Lines containing starts and ends
 	lstart <- (1:l)[start]
@@ -42,12 +157,14 @@
 	cstart <- cumsum(start)
 	cend <- cumsum(end)
 	if (any(cend > cstart))
-		stop("Incorrect SciViews R script (inversion of start and end in one or more doc chunks)")
+		stop("Incorrect SciViews Rdoc",
+			 " (inversion of start and end in one or more doc chunks)")
 	
-	## Check that it is the SciViews R script file starts with #!
+	## Check that the SciViews Rdoc file starts with #!
 	if (!grepl("^#!", Rscript[1]))
-		stop("Incorrect SciViews R script (it must start with #!)")
+		stop("Incorrect SciViews Rdoc (it must start with #!)")
 	
+	## TODO: change this into a header constructor from svSweave::Rdoc()
 	## Locate the header, which is one or several lines of initialization R code
 	inHeader <- 2:(lstart[1] - 1)
 	
@@ -60,11 +177,18 @@
 	## Convert \\ into \ inside doc blocks
 	Rscript[inDoc] <- gsub("\\\\\\\\", "\\\\", Rscript[inDoc])
 	
-	## Replace all doc chunk starters (!"@) by @
+	## Convert comments blocks using four or more #### by ////
+	Rscript[inDoc] <- gsub("^####+$", "////", Rscript[inDoc])
+	
+	## Convert line comments using ## by //
+	Rscript[inDoc] <- gsub("^##", "//", Rscript[inDoc])
+	
+	## Replace all doc chunk starters (!") by @
 	Rscript[start] <- "@"
 	
-	## Replace all doc chunk ends (<<.*>>=") by the same without trailing "
-	Rscript[end] <- sub('^(.*>>=)"[ \t]*$', "\\1", Rscript[end])
+	## Replace all doc chunk ends (!<<.*>>=") by the same without leading !
+	## and trailing "
+	Rscript[end] <- sub('!^(.*>>=)"[ \t]*$', "\\1", Rscript[end])
 	
 	## Polish the end of the document...
 	lastDoc <- lend[length(lend)]
@@ -99,32 +223,32 @@
 	return(invisible(Rscript))
 }
 
-RasciidocConvert <- function (Rfile, theme, format, show.it, figsDir,
-keepRnwFile, keepTxtFile, encoding, asciidoc)
+RdocConvert <- function (RdocFile, theme, format, show.it, figs.dir,
+keep.RnwFile, keep.TxtFile, encoding, asciidoc)
 {
-	## If Rfile is missing, try to get it from option or the command line
-	if (missing(Rfile)) Rfile <- .Rfile()
+	## If RdocFile is missing, try to get it from option or the command line
+	if (missing(RdocFile)) RdocFile <- .RdocFile()
 	
-	## RnwFile is either same place, same name as Rfile, or option sv.RnwFile
-	RnwFile <- getOption("sv.RnwFile", .fileExt(Rfile, "Rnw"))
+	## RnwFile is either same place, same name as RdocFile, or option Rnw.file
+	RnwFile <- getOption("Rnw.file", .fileExt(RdocFile, "Rnw"))
 
 	## TxtFile is from option, or from SciViews session directory structure
-	## or at the same location as the Rfile
-	TxtFile <- getOption("sv.TxtFile", .fileExt(Rfile, "txt"))
-	ReportDir <- .svSessionDirs(Rfile)$reportdir
+	## or at the same location as the RdocFile
+	TxtFile <- getOption("Txt.file", .fileExt(RdocFile, "txt"))
+	ReportDir <- .svSessionDirs(RdocFile)$reportdir
 	if (length(ReportDir)) {
 		TxtFile <- file.path(ReportDir, basename(TxtFile))
 	} else TxtFile <- TxtFile
 	## Make sure this is not an old file
 	unlink(TxtFile)
 	
-	## If figsDir is defined (default to 'figures'), make sure it exists
-	if (missing(figsDir)) figsDir <- getOption("sv.figsDir", "figures")
-	if (length(figsDir)) dir.create(file.path(dirname(TxtFile), figsDir),
+	## If figs.dir is defined (default to 'figures'), make sure it exists
+	if (missing(figs.dir)) figs.dir <- getOption("Rdoc.figs.dir", "figures")
+	if (length(figs.dir)) dir.create(file.path(dirname(TxtFile), figs.dir),
 		showWarnings = FALSE, recursive = TRUE)
 	
 	## If format is missing, try getting it from options(), or assume "html"
-	if (missing(format)) format <- getOption("sv.format", "html")
+	if (missing(format)) format <- getOption("Rdoc.format", "html")
 	## The resulting file extension depends on the format used
 	## Note that EndFile is always at same location as TxtFile
 	EndExt <- switch(format,
@@ -138,26 +262,29 @@
 		docbook = "xml",
 		docbook45 = "xml",
 		latex = "tex",
-		stop("Unknown format, use html/html4/html5/slidy/slidy2/wordpress/docbook/latex")
+		stop("Unknown format,",
+			" use html/html4/html5/slidy/slidy2/wordpress/docbook/latex")
 		)
 	EndFile <- .fileExt(TxtFile, EndExt)
 		
 	## If theme is missing, try getting it from options()
-	if (missing(theme)) theme <- getOption("sv.theme", "sciviews")
+	if (missing(theme)) theme <- getOption("Rdoc.theme", "sciviews")
 	## If there is an initialization file for this theme, run it now
 	## TODO...
 		
 	## Do we show the resulting Html file in the current browser at the end?
 	## By default YES, unless in non-interactive mode
-	if (missing(show.it)) show.it <- getOption("sv.show.it", interactive())
+	if (missing(show.it)) show.it <- getOption("Rdoc.showIt", interactive())
 	
 	## Do we keep intermediary .Rnw and .txt files? Default to FALSE
-	if (missing(keepRnwFile)) keepRnwFile <- getOption("sv.keepRnwFile", FALSE)
-	if (missing(keepTxtFile)) keepTxtFile <- getOption("sv.keepTxtFile", FALSE)
+	if (missing(keep.RnwFile))
+		keep.RnwFile <- getOption("Rdoc.keep.RnwFile", FALSE)
+	if (missing(keep.TxtFile))
+		keep.TxtFile <- getOption("Rdoc.keep.TxtFile", FALSE)
 	
-	## Get encoding... should be UTF-8 for SciViews R scripts
+	## Get encoding... should be UTF-8 for SciViews Rdoc
 	## and make sure to configure the system as UTF-8 (except on Windows)
-	if (missing(encoding)) encoding <- getOption("sv.encoding", "UTF-8")
+	if (missing(encoding)) encoding <- getOption("Rdoc.encoding", "UTF-8")
 	if (toupper(encoding) == "UTF-8") {
 		if (.Platform$OS.type != "windows") {
 			## Make sure current locale is UTF-8
@@ -185,7 +312,7 @@
 	
 	## Convert from Rscript to .Rnw file
 	cat("Creating R noweb file ", basename(RnwFile), "\n", sep = "")
-	RasciidocToRnw(Rfile = Rfile, RnwFile = RnwFile, encoding = encoding)
+	RdocToRnw(RdocFile = RdocFile, RnwFile = RnwFile, encoding = encoding)
 	if (!file.exists(RnwFile))
 		stop("Problems while creating the R noweb file(", RnwFile, ")")
 	
@@ -208,8 +335,8 @@
 		setwd(odir)
 		unlink(RnwFile2)
 		## Possibly delete intermediary files
-		if (!isTRUE(keepRnwFile)) unlink(RnwFile)
-		if (!isTRUE(keepTxtFile)) unlink(TxtFile)	
+		if (!isTRUE(keep.RnwFile)) unlink(RnwFile)
+		if (!isTRUE(keep.TxtFile)) unlink(TxtFile)	
 	})
 	
 	## Sweave this document...
@@ -235,39 +362,40 @@
 
 	## Do we view the resulting .html file?
 	if (isTRUE(show.it) && EndExt == "html") {
-		cat("Opening the formatted document", basename(EndFile), "in the Web browser\n")
+		cat("Opening the formatted document", basename(EndFile),
+			"in the Web browser\n")
 		browseURL(normalizePath(EndFile))
 	} else cat("Formatted document available at ", EndFile, "\n", sep = "")
 }
 
-RasciidocThemes <- function ()
+RdocThemes <- function ()
 {
 	themesDir <- file.path(dirname(system.file("asciidoc", "asciidoc.py",
 		package = "svSweave")), "themes")
 	c("classic", dir(themesDir, include.dirs = TRUE))
 }
 
-svBuild <- function (Rfile, encoding)
+makeRdoc <- function (RdocFile, encoding)
 {
-	## A function to run an a SciViews R script file, and that looks at the #!
+	## A function to run an a SciViews Rdoc file, and that looks at the #!
 	## line to determine what function to run for compiling the final document
 
-	## Check Rfile
-	if (missing(Rfile) || !length(Rfile)) stop("No file provided")
-	if (!file.exists(Rfile)) stop("Rfile not found (", Rfile, ")")
-	Rfile <- normalizePath(Rfile)
+	## Check RdocFile
+	if (missing(RdocFile) || !length(RdocFile)) stop("No file provided")
+	if (!file.exists(RdocFile)) stop("RdocFile not found (", RdocFile, ")")
+	RdocFile <- normalizePath(RdocFile)
 	
 	## Get encoding
-	if (missing(encoding)) encoding <- getOption("sv.encoding", "UTF-8")	
+	if (missing(encoding)) encoding <- getOption("Rdoc.encoding", "UTF-8")	
 	
 	## Check that it is a R script file (first line starting with #!)
-	Rscript <- readLines(Rfile, n = 1L, encoding = encoding)
+	Rscript <- readLines(RdocFile, n = 1L, encoding = encoding)
 	if (!grepl("^#!", Rscript))
-		stop("Incorrect SciViews R script (it must start with #!)")
+		stop("Incorrect SciViews Rdoc file (it must start with #!)")
 
-	## Decrypt first line to know what function to run to build this file
+	## Decrypt first line to know what function to run to make this file
 	cmd <- sub("^#!.+ -e[ \t]*(.+)$", "\\1", Rscript)
-	if (cmd == Rscript) stop("Malformed #! line in '", Rfile, "'")
+	if (cmd == Rscript) stop("Malformed #! line in '", RdocFile, "'")
 	
 	## Eliminate possible quotes around the command and trailing spaces
 	cmd <- sub("[ \t]+$", "", cmd)
@@ -276,9 +404,9 @@
 		cmdNoQuotes <- sub('^"(.+)"$', "\\1", cmd) # Double quotes
 	
 	## Pass the file name to the build procedure
-	ofile <- options(sv.Rfile = Rfile)$sv.Rfile
-	oencoding <- options(sv.encoding = encoding)$sv.encoding
-	on.exit(options(sv.Rfile = ofile, encoding = oencoding))
+	ofile <- options(Rdoc.file = RdocFile)$Rdoc.file
+	oencoding <- options(Rdoc.encoding = encoding)$Rdoc.encoding
+	on.exit(options(Rdoc.file = ofile, encoding = oencoding))
 	
 	## Run that command
 	cmd <- try(parse(text = cmdNoQuotes))

Modified: pkg/svSweave/R/svSweave-internal.R
===================================================================
--- pkg/svSweave/R/svSweave-internal.R	2013-01-01 21:09:34 UTC (rev 503)
+++ pkg/svSweave/R/svSweave-internal.R	2013-01-02 11:34:43 UTC (rev 504)
@@ -11,18 +11,18 @@
 {
 	## Change the extension of a file
 	file <- sub("\\.[^\\.]*$", "", file)
-	return(paste(file, extension, sep = "."))
+	paste(file, extension, sep = ".")
 }
 
-.Rfile <- function ()
+.RdocFile <- function ()
 {
-	## Try to get Rfile from option or the command line
+	## Try to get RdocFile from option or the command line
 	## Note: the file from the command line is for #! scripts!
-	Rfile <- getOption("sv.Rfile", NULL)
-	if (is.null(Rfile)) Rfile <- commandArgs(TRUE)[1] # If #! script
-	if (!length(Rfile) || !file.exists(Rfile))
-		stop("Rfile not found (", Rfile, ")")
-	return(normalizePath(Rfile, winslash = "/"))
+	RdocFile <- getOption("Rdoc.file", NULL)
+	if (is.null(RdocFile)) RdocFile <- commandArgs(TRUE)[1] # If #! script
+	if (!length(RdocFile) || !file.exists(RdocFile))
+		stop("RdocFile not found (", RdocFile, ")")
+	return(normalizePath(RdocFile, winslash = "/"))
 	
 }
 
@@ -86,7 +86,8 @@
 		#pyVersion <- sub("^Python ", "",
 		#	system(paste('"', py, '" --version 2>&1', sep = ""), intern = TRUE))
 		pyVersion <- sub("^([^ ]+).*$", "\\1", system(paste('"', py,
-			'" -c "import sys; print sys.version"', sep = ""), intern = TRUE)[1])
+			'" -c "import sys; print sys.version"', sep = ""),
+			intern = TRUE)[1])
 		res <- try(suppressWarnings(compareVersion(pyVersion, "2.4") > 0),
 			silent = TRUE)
 		## If there is an error, by-pass version checking and just look if

Modified: pkg/svSweave/R/tangleLyxRnw.R
===================================================================
--- pkg/svSweave/R/tangleLyxRnw.R	2013-01-01 21:09:34 UTC (rev 503)
+++ pkg/svSweave/R/tangleLyxRnw.R	2013-01-02 11:34:43 UTC (rev 504)
@@ -1,3 +1,6 @@
+## TODO: merge both functions and use a tag in the document to decide
+##       if using sweave or knitr
+
 tangleLyxRnw <- function (file, driver = Rtangle(),
 syntax = getOption("SweaveSyntax"), encoding = "UTF-8", width = 80,
 useFancyQuotes = TRUE, annotate = TRUE, ...)

Modified: pkg/svSweave/R/weaveLyxRnw.R
===================================================================
--- pkg/svSweave/R/weaveLyxRnw.R	2013-01-01 21:09:34 UTC (rev 503)
+++ pkg/svSweave/R/weaveLyxRnw.R	2013-01-02 11:34:43 UTC (rev 504)
@@ -1,4 +1,6 @@
 ## TODO: see the tables package for better looking tables, including in LaTeX!
+## TODO: merge both functions and use a tag in the document to decide
+##       if using sweave or knitr
 
 weaveLyxRnw <- function (file, driver = RweaveLatex(),
 syntax = getOption("SweaveSyntax"), encoding = "UTF-8", width = 80,

Added: pkg/svSweave/man/Rdoc.Rd
===================================================================
--- pkg/svSweave/man/Rdoc.Rd	                        (rev 0)
+++ pkg/svSweave/man/Rdoc.Rd	2013-01-02 11:34:43 UTC (rev 504)
@@ -0,0 +1,117 @@
+\name{Rdoc}
+\alias{Rdoc}
+
+\title{ Create an Rdoc header to be processed with Asciidoc }
+\description{
+  SciViews R docs have a couple of obligatory first lines. After one line
+  specifying how to process the document if it is made executables
+  (\code{#! /usr/bin/Rscript -e 'svSweave::makeRdoc()'}), one must call
+  \code{Rdoc()} to create a correct header to be processed by Asciidoc and
+  Sweave. Usually, you follow this instruction by \code{require(SciViews)},
+  which you need to deal with doc chunks (\code{!"... !<<>>="}), and you start
+  then the document with a doc chunk (usually with the abstract). See example.
+}
+
+\usage{
+Rdoc(title, author, email, revnumber = NULL, revdate = NULL,
+revremark = NULL, copyright = "cc-by", encoding = "utf-8", lang = "en",
+pagetitle = NULL, description = "SciViews Rdoc", keywords = NULL,
+format = "html", theme = "SciViews", max.width = 720, width = "100\%",
+toc = c("top", "side", "manual", "none"), toc.title = NULL, toclevels = 3,
+numbered = TRUE, data.uri = TRUE, frame = "topbot", grid = "rows",
+align = "center", halign = "center", pygments = FALSE, slidefontsizeadjust = 0,
+SweaveOpts = list(prefix.string = "figures/fig", width = 7.2, height = 7.2,
+    pdf = TRUE), SweaveInit = { options(width = 90); options(SweaveHooks =
+    list(fig = function() par(col.lab = "#434366", col.main = "#434366")))}
+)
+}
+
+\arguments{
+  \item{title}{ a character string with the title of your SciViews Rdoc. }
+  \item{author}{ a character string with the name of the author. You can specify
+    first [middle] [last], and each item cannot contain spaces (replace them
+    by underscores _). }
+  \item{email}{ a character string with a valid email address. }
+  \item{revnumber}{ a character string with the revision number of your SciViews
+    Rdoc. If \code{NULL}, it is omitted. }
+  \item{revdate}{ a character string with the revision date of your SciViews
+    Rdoc. It must be Month Year format, e.g., \code{January 2013}. From a Date
+    object, you got the right format using \code{format(myDate, format = '\%B \%Y')}.
+    If \code{NULL}, current date is used. }
+  \item{revremark}{ a character string with one or more sentences describing the
+    current revision. If \code{NULL}, it is omitted. }
+  \item{copyright}{ a character string with either a complete copyright like
+    cc-by, John Does, 2013, or just the first part (cc-by) and the author and
+    year will be appended automatically. If \code{NULL}, it is omitted. }
+  \item{encoding}{ a character string with the encoding of your SciViews Rdoc.
+    It is not advised to change from the default, utf-8. Make sure you save
+    your document in UTF-8 encoding before you process it! }
+  \item{lang}{ the (main) language used in your SciViews Rdoc. By default, it is
+    English (en), but Asciidoc can also use de, el, es, fr, hu, it, nl, pt, ru
+    or uk. }
+  \item{pagetitle}{ a character string with the title that should appear in the
+    browser's tab. If \code{NULL}, it is the same one as the Rdoc title. }
+  \item{description}{ a character string with the description of the document
+    to use in the head section of the HTML document. If \code{NULL}, it is
+    omitted. }
+  \item{keywords}{ a character string with one or more keywords to use in the
+    head section of the HTML document. If \code{NULL}, it is omitted. }
+  \item{format}{ a character string with the format into which the Rdoc should
+    be converted. By default (\code{"html"}), an HTML document is compiled. Valid
+    formats are: html, html4, html5, slidy, slidy2, wordpress, docbook,
+    docbook45 and latex (see the AsciiDoc man page). } 
+  \item{theme}{ the theme to use with the Asciidoc HTML file. By default, it is
+    \code{"SciViews"}. }
+  \item{max.width}{ the maximum width of the page, in pixels or in percent.
+    If \code{NULL}, it is omited. }
+  \item{width}{ the width of the page, in pixels or in percent. If \code{NULL},
+    it is omited. }
+  \item{toc}{ should a table of contents be generated? With \code{"top"}, it is
+    automatically placed at the top of the document, with \code{"side"}, it is
+    placed at left (unless otherwise specified in the CSS style). With
+    \code{"manual"}, it is generated but not placed automatically. Use
+    \code{toc::[]} on one line in a doc chunk to indicate where to place it.
+    Finally, with \code{"none"}, the tabel of contents is not generated. }
+  \item{toc.title}{ the title of your table of contents. If \code{NULL}, the
+    default (Table of Contents, or its translation in the main language of the
+    SciViews Rdoc) is used. }
+  \item{toclevels}{ how deep in title levels should the table of contents be
+    generated (1, 2, 3 or 4)? By default, it is 3. }
+  \item{numbered}{ should the titles be numbered (\code{TRUE}, by default), or
+    not (\code{FALSE})? }
+  \item{data.uri}{ should figures, scripts and styles be embedded in the main
+    HTML document, using data-uri fields (\code{TRUE} by default)? }
+  \item{frame}{ frames to draw for tables. By default (\code{"topbot"}) at the
+    top and the bottom of the table. }
+  \item{grid}{ which grid should be drawn for tables. By default (\code{"rows"}),
+    only row grid lines are drawn. }
+  \item{align}{ default alignment of figures and whole tables (\code{"center"}
+    by default). }
+  \item{halign}{ horizontal alignment of text inside table cells (\code{"center"},
+    by default). }
+  \item{pygments}{ should pygments be used for syntax highlighting of code?
+    \code{FALSE} by default. }
+  \item{slidefontsizeadjust}{ adjustment of font size in slidy and slidy2
+    documents. }
+  \item{SweaveOpts}{ options for Sweave. A reasonable default is provided.
+    See ?sweave. }
+  \item{SweaveInit}{ code to be run in the init code chunk, related to sweave.
+    Reasonable defaults are provided. See ?sweave. }
+}
+
+\value{
+  The header is returned invisibly.
+}
+
+\author{ Philippe Grosjean <phgrosjean at sciviews.org> }
+
+\seealso{ \code{\link{RdocToRnw}} }
+
+\examples{
+## A minimal Rdoc contained in a string:
+## TODO...
+}
+
+\keyword{ utilities }
+
+\concept{ Literate programming, weaving, tangling Asciidoc files }

Modified: pkg/svSweave/man/asciidoc.Rd
===================================================================
--- pkg/svSweave/man/asciidoc.Rd	2013-01-01 21:09:34 UTC (rev 503)
+++ pkg/svSweave/man/asciidoc.Rd	2013-01-02 11:34:43 UTC (rev 504)
@@ -1,30 +1,30 @@
 \name{asciidoc}
-\alias{RasciidocToRnw}
-\alias{RasciidocConvert}
-\alias{RasciidocThemes}
-\alias{svBuild}
+\alias{RdocToRnw}
+\alias{RdocConvert}
+\alias{RdocThemes}
+\alias{makeRdoc}
 
-\title{ Transform SciViews R scripts into R noweb or HTML files }
+\title{ Transform SciViews Rdocs into R noweb or HTML files }
 \description{
-  SciViews R scripts are R-compatible scripts that embed Sweave code and doc
+  SciViews Rdocs are R-compatible scripts that embed Sweave code and doc
   blocks to format text between R chunks. These functions convert such scripts
   into R noweb files that can be processed by Sweave, or in the case of
   Asciidoc version, into HTML files after running Sweave and Asciidoc.
 }
 
 \usage{
-RasciidocToRnw(Rfile, RnwFile, encoding)
-RasciidocConvert(Rfile, theme, format, show.it, figsDir, keepRnwFile,
-    keepTxtFile, encoding, asciidoc)
-RasciidocThemes()
-svBuild(Rfile, encoding)
+RdocToRnw(RdocFile, RnwFile, encoding)
+RdocConvert(RdocFile, theme, format, show.it, figs.dir, keep.RnwFile,
+    keep.TxtFile, encoding, asciidoc)
+RdocThemes()
+makeRdoc(RdocFile, encoding)
 }
 
 \arguments{
-  \item{Rfile}{ a character string corresponding to the path to a SciViews R
-    script file to be converted. }
-  \item{RnwFile}{ idem, but the R noweb file to create. Default to same file, but
-    with \code{.Rnw} extension. }
+  \item{RdocFile}{ a character string corresponding to the path to a SciViews
+    Rdoc file to be converted. }
+  \item{RnwFile}{ idem, but the R noweb file to create. Default to same file,
+    but with \code{.Rnw} extension. }
   \item{encoding}{ the encoding of the .R and .Rnw files. It is \code{UTF-8} by
     default, but you can change it here. }
   \item{theme}{ the theme to use with the Asciidoc HTML file. By default, it is
@@ -35,21 +35,22 @@
     (see the AsciiDoc man page). }
   \item{show.it}{ is the resulting HTML file shown in the default browser.
     Default value depends if R is run interactively or not. }
-  \item{figsDir}{ subdirectory where to place figures (R plots) when compiling
+  \item{figs.dir}{ subdirectory where to place figures (R plots) when compiling
     Sweave files. Default is \code{"figures"}. Just check that the directory
     exists (otherwise, Sweave fails to produce the plots). }
-  \item{keepRnwFile}{ is the generated R noweb file kept at the end? }
-  \item{keepTxtFile}{ is the generated Asciidoc \code{.txt} file kept at the end? }
+  \item{keep.RnwFile}{ is the generated R noweb file kept at the end? }
+  \item{keep.TxtFile}{ is the generated Asciidoc \code{.txt} file kept at the
+    end? }
   \item{asciidoc}{ path to the asciidoc Python script; By default, the version
     included in this package is used. }
 }
 
 \value{
-  The text of the R noweb data is returned invisibly by \code{RasciidocToRnw()}.
-  \code{NULL} is returned by \code{RasciidocConvert()} (this function is invoked for
-  its side effect. \code{RasciidocThemes()} returns the list of themes
-  available for your HTML documents. Finally, \code{svBuild()} is a convenient
-  function to automatically build a report from a SciViews R script.
+  The text of the R noweb data is returned invisibly by \code{RdocToRnw()}.
+  \code{NULL} is returned by \code{RdocConvert()} (this function is invoked for
+  its side effect. \code{RdocThemes()} returns the list of themes
+  available for your HTML documents. Finally, \code{makeRdoc()} is a convenient
+  function to automatically build a report from a SciViews Rdoc.
 }
 
 \details{
@@ -59,6 +60,8 @@
 
 \author{ Philippe Grosjean <phgrosjean at sciviews.org> }
 
+\seealso{ \code{\link{Rdoc}} }
+
 \keyword{ utilities }
 
 \concept{ Literate programming, weaving, tangling Asciidoc files }

Modified: pkg/svSweave/man/cleanLyxRnw.Rd
===================================================================
--- pkg/svSweave/man/cleanLyxRnw.Rd	2013-01-01 21:09:34 UTC (rev 503)
+++ pkg/svSweave/man/cleanLyxRnw.Rd	2013-01-02 11:34:43 UTC (rev 504)
@@ -5,7 +5,8 @@
 \alias{knitLyxRnw}
 \alias{purlLyxRnw}
 
-\title{ Clean up, weave or tangle Sweave files produced by LyX with the SciViews Sweave module }
+\title{ 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!)
@@ -50,10 +51,12 @@
 
 \value{
   \code{NULL}, these functions are invoked for their side effects. The function
-  \code{weaveLyxRnw()} uses the standard Sweave driver, while \code{knitLyxRnw()}
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/sciviews -r 504


More information about the Sciviews-commits mailing list