[Sciviews-commits] r46 - komodo komodo/SciViews-K komodo/SciViews-K/content/js komodo/SciViews-K/skin komodo/SciViews-K/templates pkg/svMisc/R pkg/svMisc/man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jul 7 03:38:46 CEST 2008
Author: phgrosjean
Date: 2008-07-07 03:38:43 +0200 (Mon, 07 Jul 2008)
New Revision: 46
Added:
komodo/SciViews-K/templates/SciViews-K.kpz
komodo/SciViews-K/templates/svGUI_0.9-42.tar.gz
komodo/SciViews-K/templates/svGUI_0.9-42.tgz
komodo/SciViews-K/templates/svGUI_0.9-42.zip
komodo/SciViews-K/templates/svMisc_0.9-44.tar.gz
komodo/SciViews-K/templates/svMisc_0.9-44.tgz
komodo/SciViews-K/templates/svMisc_0.9-44.zip
komodo/SciViews-K/templates/svSocket_0.9-41.tar.gz
komodo/SciViews-K/templates/svSocket_0.9-41.tgz
komodo/SciViews-K/templates/svSocket_0.9-41.zip
pkg/svMisc/R/descFun.R
pkg/svMisc/man/descFun.Rd
Removed:
komodo/SciViews-K/templates/SciViews-K 0.6.3.kpz
Modified:
komodo/.DS_Store
komodo/SciViews-K/.DS_Store
komodo/SciViews-K/content/js/sciviews.js
komodo/SciViews-K/sciviewsk-0.6.3-ko.xpi
komodo/SciViews-K/skin/sciviewsk_console.css
komodo/SciViews-K/templates/.DS_Store
komodo/SciViews-K/templates/.Rprofile
Log:
SciViews-K modified for an easier installation
Modified: komodo/.DS_Store
===================================================================
(Binary files differ)
Modified: komodo/SciViews-K/.DS_Store
===================================================================
(Binary files differ)
Modified: komodo/SciViews-K/content/js/sciviews.js
===================================================================
--- komodo/SciViews-K/content/js/sciviews.js 2008-07-06 13:30:08 UTC (rev 45)
+++ komodo/SciViews-K/content/js/sciviews.js 2008-07-07 01:38:43 UTC (rev 46)
@@ -5,7 +5,9 @@
////////////////////////////////////////////////////////////////////////////////
// sv.version; // Get current SciViews-K version (major.minor)
// sv.release; // The release (bug fixes). Full version is "version.release"
+// sv.showVersion; // Do we display version in an alert() box or just set it?
// sv.checkVersion(version); // Check if the OpenKore extension version is fine
+// sv.checkToolbox(); // Check that the correct SciViews-K toolbox is installed
//
// Various functions defined in the 'sv' namespace directly
// sv.getText(); // Get current selection, or word under the cursor
@@ -33,7 +35,8 @@
sv = {
// TODO: set this automatically according to the plugin version
version: 0.6,
- release: 0,
+ release: 3,
+ showVersion: true,
checkVersion: function(version) {
if (this.version < version) {
var title = "SciViews-K"
@@ -383,3 +386,55 @@
} finally { scimoz.readOnly = ro; }
} catch(e) { alert("problems clearing the Command Output pane\n"); }
};
+
+sv.checkToolbox = function() {
+ try {
+ var pkg = ko.interpolate.interpolateStrings("%(path:hostUserDataDir)");
+ pkg += "/XRE/extensions/sciviewsk at sciviews.org/templates/SciViews-K.kpz";
+ var partSvc = Components.classes["@activestate.com/koPartService;1"]
+ .getService(Components.interfaces.koIPartService);
+ var SciViewsK_folders = partSvc.getParts("folder", "name", "SciViews-K",
+ "*", partSvc.currentProject, new Object());
+ if (SciViewsK_folders.length == 0) {
+ // The SciViews-K toolbox is not installed yet... do it now
+ ko.toolboxes.importPackage(pkg);
+ } else {
+ // First, eliminate all SciViews-K toolboxes that are too old
+ var VersionMacro;
+ var SciViewsK_folder;
+ sv.showVersion = false;
+ for (var i = 0; i < SciViewsK_folders.length; i++) {
+ SciViewsK_folder = SciViewsK_folders[i];
+ VersionMacro = SciViewsK_folder.getChildWithTypeAndStringAttribute(
+ "macro", "name", "Version", true);
+ if (VersionMacro) {
+ ko.projects.executeMacro(VersionMacro);
+ if (SciViewsKtoolboxVersion < sv.version) {
+ // This toolbox is too old for our extension
+ ko.toolboxes.user.removeItem(SciViewsK_folder, true);
+ }
+ } else {
+ // Probably a corrupted SciViews-K toolbox => eliminate it
+ ko.toolboxes.user.removeItem(SciViewsK_folder, true);
+ }
+ }
+ // Recheck how many SciViews-K toolboxes are left
+ SciViewsK_folders = partSvc.getParts("folder", "name", "SciViews-K",
+ "*", partSvc.currentProject, new Object());
+ if (SciViewsK_folders.length == 0) {
+ // Install the new one now
+ ko.toolboxes.importPackage(pkg);
+ } else if (SciViewsK_folders.length > 1) {
+ // There are duplications, keep only last one
+ for (var i = 0; i < (SciViewsK_folders.length - 1); i++) {
+ SciViewsK_folder = SciViewsK_folders[i];
+ ko.toolboxes.user.removeItem(SciViewsK_folder, true);
+ }
+ }
+ }
+ } catch(e) { alert(e); }
+ finally { sv.showVersion = true; }
+}
+
+// Ensure we check the toolbox is installed once the extension is loaded
+addEventListener("load", sv.checkToolbox, false);
\ No newline at end of file
Modified: komodo/SciViews-K/sciviewsk-0.6.3-ko.xpi
===================================================================
(Binary files differ)
Modified: komodo/SciViews-K/skin/sciviewsk_console.css
===================================================================
--- komodo/SciViews-K/skin/sciviewsk_console.css 2008-07-06 13:30:08 UTC (rev 45)
+++ komodo/SciViews-K/skin/sciviewsk_console.css 2008-07-07 01:38:43 UTC (rev 46)
@@ -1,7 +1,7 @@
.historyPre{
margin:0px;
padding:0px;
- font-family: Courier new, monospace;
+ font-family: Monaco, "Courier new", monospace;
}
.historyListitem{
@@ -16,13 +16,13 @@
.consoleInput{
border-top: 1px solid #666666 ;
color: blue;
- font-family:Courier New, monospace;
+ font-family: Monaco, "Courier New", monospace;
margin:0px;
}
.consoleOutput{
color:black;
- font-family:Courier New, monospace;
+ font-family: Monaco, "Courier New", monospace;
margin-bottom: 10px;
margin-top: 0px;
}
@@ -33,7 +33,7 @@
border-bottom:none;
border-left: none;
border-right:none;
- font-family: Courier New, monospace;
+ font-family: Monaco, "Courier New", monospace;
font-weight: bold;
background-color: #dddddd ;
}
Modified: komodo/SciViews-K/templates/.DS_Store
===================================================================
(Binary files differ)
Modified: komodo/SciViews-K/templates/.Rprofile
===================================================================
--- komodo/SciViews-K/templates/.Rprofile 2008-07-06 13:30:08 UTC (rev 45)
+++ komodo/SciViews-K/templates/.Rprofile 2008-07-07 01:38:43 UTC (rev 46)
@@ -1,20 +1,29 @@
### SciViews install begin ###
# SciViews-R installation and startup for running R with Komodo/SciViews-K
-# Merge this with your .Rprofile file in your home directory to configure
-# R automatically at startup
+# Version 0.6.3, 2008-07-06 Ph. Grosjean (phgrosjean at sciviews.org)
# Make sure we don't process this twice in case of duplicate items in .Rprofile
if (!exists(".SciViewsReady", envir = .GlobalEnv)) {
.SciViewsReady <- FALSE
- minVersion <- c(R = "2.7.0", svMisc = "0.9-42", svSocket = "0.9-41", svGUI = "0.9-42")
+ minVersion <- c(R = "2.7.0", svMisc = "0.9-44", svSocket = "0.9-41", svGUI = "0.9-42")
+ # Get environment variables
+ args <- commandArgs()
+
# Configure socket client/server
- options(ko.serve = 8888) # Port used by the R socket server
- options(ko.host = "localhost") # Machine where Komodo is running (local only for the moment)
- options(ko.port = 7052) # Port used by the Komodo socket server
- options(ko.id = "R") # The id used for this R kernel in Komodo
- options(ko.activate = FALSE) # Do we start/activate Komodo at startup?
- # Note: set ko.activate to TRUE causes problems currently!
+ par <- args[grep("^--ko.serve=", args)]
+ if (length(par) == 0) par <- 8888 else par <- as.integer(sub("^--ko.serve=", "", par))
+ options(ko.serve = par) # Port used by the R socket server
+ par <- args[grep("^--ko.host=", args)]
+ if (length(par) == 0) par <- "localhost" else par <- sub("^--ko.host=", "", par)
+ options(ko.host = par) # Machine where Komodo is running (local only for the moment)
+ par <- args[grep("^--ko.port=", args)]
+ if (length(par) == 0) par <- 7052 else par <- as.integer(sub("^--ko.port=", "", par))
+ options(ko.port = par) # Port used by the Komodo socket server
+ par <- args[grep("^--ko.id=", args)]
+ if (length(par) == 0) par <- "R" else par <- sub("^--ko.id=", "", par)
+ options(ko.id = par) # The id used for this R kernel in Komodo
+ rm(par)
# Load main R packages
res <- require(methods, quietly = TRUE)
@@ -71,51 +80,75 @@
cat("R is too old for this version of SciViews, please, upgrade it\n")
} else {
# Load packages svMisc, svSocket & svGUI (possibly after installing
- # or upgrading them). User is supposed to have agreed
+ # or upgrading them). User is supposed to agree with this install
+ # from the moment he tries to start and configure R from Komodo Edit
+ ext <- switch(.Platform$pkgType,
+ mac.binary = "\\.tgz",
+ win.binary = "\\.zip",
+ "\\.tar.gz")
## svMisc
+ file <- dir(pattern = paste("svMisc", ext, sep = ".+"))
+ file <- sort(file)[length(file)] # Keep oldest one
desc <- system.file("DESCRIPTION", package = "svMisc")
if (desc == "") {
- cat("Trying to install missing package 'svMisc'\n")
- install.packages("svMisc", repos = "http://R-Forge.R-project.org")
- res <- require(svMisc, quietly = TRUE)
+ cat("Installing missing package 'svMisc'\n")
+ if (length(file)) {
+ install.packages(file, repos = NULL) # or use "http://R-Forge.R-project.org"
+ res <- require(svMisc, quietly = TRUE)
+ } else res <- FALSE
} else { # Check version
if ((compareVersion(packageDescription("svMisc", fields = "Version"),
minVersion["svMisc"]) < 0)) {
- cat("Trying to update package 'svMisc'\n")
- install.packages("svMisc", repos = "http://R-Forge.R-project.org")
- }
- res <- require(svMisc, quietly = TRUE)
+ cat("Updating package 'svMisc'\n")
+ if (length(file)) {
+ install.packages(file, repos = NULL)
+ res <- require(svMisc, quietly = TRUE)
+ } else res <- FALSE
+ } else res <- require(svMisc, quietly = TRUE)
}
## svSocket
+ file <- dir(pattern = paste("svSocket", ext, sep = ".+"))
+ file <- sort(file)[length(file)] # Keep oldest one
desc <- system.file("DESCRIPTION", package = "svSocket")
if (desc == "") {
- cat("Trying to install missing package 'svSocket'\n")
- install.packages("svSocket", repos = "http://R-Forge.R-project.org")
- res[2] <- require(svSocket, quietly = TRUE)
+ cat("Installing missing package 'svSocket'\n")
+ if (length(file)) {
+ install.packages(file, repos = NULL)
+ res[2] <- require(svSocket, quietly = TRUE)
+ } else res[2] <- FALSE
} else { # Check version
if ((compareVersion(packageDescription("svSocket", fields = "Version"),
minVersion["svSocket"]) < 0)) {
- cat("Trying to update package 'svSocket'\n")
- install.packages("svSocket", repos = "http://R-Forge.R-project.org")
- }
- res[2] <- require(svSocket, quietly = TRUE)
+ cat("Updating package 'svSocket'\n")
+ if (length(file)) {
+ install.packages(file, repos = NULL)
+ res[2] <- require(svSocket, quietly = TRUE)
+ } else res[2] <- FALSE
+ } else res[2] <- require(svSocket, quietly = TRUE)
}
## svGUI
+ file <- dir(pattern = paste("svGUI", ext, sep = ".+"))
+ file <- sort(file)[length(file)] # Keep oldest one
desc <- system.file("DESCRIPTION", package = "svGUI")
+ res[3] <- TRUE
if (desc == "") {
- cat("Trying to install missing package 'svGUI'\n")
- install.packages("svGUI", repos = "http://R-Forge.R-project.org")
+ cat("Installing missing package 'svGUI'\n")
+ if (length(file)) {
+ install.packages(file, repos = NULL)
+ } else res[3] <- FALSE
} else { # Check version
if ((compareVersion(packageDescription("svGUI", fields = "Version"),
minVersion["svGUI"]) < 0)) {
- cat("Trying to update package 'svGUI'\n")
- install.packages("svGUI", repos = "http://R-Forge.R-project.org")
+ cat("Updating package 'svGUI'\n")
+ if (length(file)) {
+ install.packages(file, repos = NULL)
+ } else res[3] <- FALSE
}
}
- rm(desc)
+ rm(desc, ext, file)
# Try starting the R socket server
if (inherits(try(startSocketServer(port = getOption("ko.serve")),
@@ -125,27 +158,11 @@
cat("Solve the problem, then type: require(svGUI)\n")
} else {
# Finally, load svGUI
- res[3] <- require(svGUI, quietly = TRUE)
+ if (res[3]) res[3] <- require(svGUI, quietly = TRUE)
if (all(res)) {
cat("R is SciViews ready!\n")
.SciViewsReady <- TRUE
- if (is.null(getOption("ko.id"))) options(ko.id = "R") # Default
- # Do we (re)activate Komodo now?
- koact <- getOption("ko.activate")
- if (is.null(koact)) koact <- FALSE
- if (koact[1]) {
- if ((.Platform$pkgType == "mac.binary")) {
- Res <- system("osascript -e 'tell application \"Komodo\" to activate'",
- intern = TRUE)
- rm(Res)
- } ### TODO: the same under Windows and Linux
- # Indicate to Komodo that R is ready
- koCmd('ko.statusBar.AddMessage("<<<data>>>", "R", 10000, true);',
- data = paste("'", getOption("ko.id"), "' (R ", R.Version()$major, ".",
- R.Version()$minor, ") connected", sep = ""))
- }
- rm(koact)
} else {
cat("R is not SciViews ready, install latest svMisc, svSocket & svGUI packages\n")
}
@@ -153,17 +170,87 @@
}
}
- # Clean up .GlobalEnv
- rm(minVersion, res)
-
# Make sure Komodo is started now
- # Note: in Mac OS X, you have to create the symbolic link manually as explained in the Komodo Help with:
+ # Note: in Mac OS X, you have to create the symbolic link manually as explained
+ # in the Komodo Help with:
# sudo ln -s "/Applications/Komodo Edit.app/Contents/MacOS/komodo" /usr/local/bin/komodo
- # Or the script will complain with: /bin/sh: line 1: komodo: command not found.
- system("komodo", wait = FALSE)
+ # You must issue something similar too under Linux (see Komodo installation guide)
+ # Or the script will complain.
- # Make sure to use Komodo as your R editor
-
+ ## Don't need this here, since R is supposed to be started from within Komodo!
+ #system("komodo", wait = FALSE)
+
+ # Look if and where komodo is installed
+ if (.Platform$OS.type == "unix") {
+ Komodo <- "/usr/local/bin/komodo"
+ # Check that this file exists
+ if (!file.exists(Komodo)) {
+ # File not found, display a message with missing link
+ Komodo <- NULL
+ # TODO: look why I can't find Komodo on Linux Ubuntu
+ #cat("Komodo is not found by R. Please, follow instructions at\n",
+ # "http://www.sciviews.org/SciViews-K to install it correctly.\n",
+ # "In particular, you must create a symbolic link in /user/local/bin:\n",
+ # "sudo ln -s <KomodoBinLocation>/komodo /usr/local/bin/komodo\n",
+ # "otherwise, R cannot find it!\n")
+ } else {
+ # Change the editor and the pager to Komodo
+ options(editor = Komodo)
+ #TODO: we need something else here: options(pager = Komodo)
+ }
+ } else {
+ # TODO: this does not seem to work, becasue the path with spaces is not recognized?
+ Komodo <- "komodo" # On Windows, 'komodo' should be enough
+ owarn <- getOption("warn")
+ options(warn = -1)
+ res <- try(system(Komodo, wait = FALSE), silent = TRUE)
+ if (res == -1) {
+ Komodo <- NULL
+ # cat("R cannot find Komodo. Please, make sure you install it correctly\n",
+ # "You can find it at http://www.activestate.com/Products/komodo_edit.\n")
+ } else {
+ # Change the editor and the pager to Komodo
+ options(editor = Komodo)
+ #TODO: we need something else here: options(pager = Komodo)
+ }
+ options(warn = owarn)
+ rm(owarn)
+ }
+ rm(minVersion, res)
+
+ # Change the working directory to the users working dir (by default) or to
+ # the directory that is specified in --dir=
+ dir <- args[grep("^--dir=", args)]
+ if (length(dir) == 0) {
+ dir <- "~" # Use home directory as default one
+ } else dir <- sub("^--dir=", "", dir)
+ setwd(dir)
+
+ # Do we load .RData and .Rhistory?
+ if (!"--no-restore" %in% args && !"--no.restore-data" %in% args)
+ if (file.exists(".RData")) load(".RData")
+ if (!"--no-restore" %in% args && !"--no.restore-history" %in% args)
+ if (file.exists(".Rhistory")) loadhistory()
+
+ # Do we reactivate Komodo now?
+ koact <- getOption("ko.activate")
+ if (is.null(koact)) {
+ koact <- "--ko-activate" %in% args
+ options(ko.activate = koact)
+ }
+ if (.SciViewsReady && isTRUE(koact)) {
+ if ((.Platform$pkgType == "mac.binary")) {
+ system("osascript -e 'tell application \"Komodo\" to activate'",
+ intern = TRUE)
+ } else if (!is.null(Komodo)) {
+ # TODO: The following start komodo if not started yet, but does not activate it!
+ system(Komodo, wait = FALSE)
+ }
+ # Indicate to Komodo that R is ready
+ koCmd('ko.statusBar.AddMessage("<<<data>>>", "R", 10000, true);',
+ data = paste("'", getOption("ko.id"), "' (R ", R.Version()$major, ".",
+ R.Version()$minor, ") connected", sep = ""))
+ }
+ rm(koact, Komodo, args, dir)
}
-
### SciViews install end ###
\ No newline at end of file
Deleted: komodo/SciViews-K/templates/SciViews-K 0.6.3.kpz
===================================================================
(Binary files differ)
Added: komodo/SciViews-K/templates/SciViews-K.kpz
===================================================================
(Binary files differ)
Property changes on: komodo/SciViews-K/templates/SciViews-K.kpz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: komodo/SciViews-K/templates/svGUI_0.9-42.tar.gz
===================================================================
(Binary files differ)
Property changes on: komodo/SciViews-K/templates/svGUI_0.9-42.tar.gz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: komodo/SciViews-K/templates/svGUI_0.9-42.tgz
===================================================================
(Binary files differ)
Property changes on: komodo/SciViews-K/templates/svGUI_0.9-42.tgz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: komodo/SciViews-K/templates/svGUI_0.9-42.zip
===================================================================
(Binary files differ)
Property changes on: komodo/SciViews-K/templates/svGUI_0.9-42.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: komodo/SciViews-K/templates/svMisc_0.9-44.tar.gz
===================================================================
(Binary files differ)
Property changes on: komodo/SciViews-K/templates/svMisc_0.9-44.tar.gz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: komodo/SciViews-K/templates/svMisc_0.9-44.tgz
===================================================================
(Binary files differ)
Property changes on: komodo/SciViews-K/templates/svMisc_0.9-44.tgz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: komodo/SciViews-K/templates/svMisc_0.9-44.zip
===================================================================
(Binary files differ)
Property changes on: komodo/SciViews-K/templates/svMisc_0.9-44.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: komodo/SciViews-K/templates/svSocket_0.9-41.tar.gz
===================================================================
(Binary files differ)
Property changes on: komodo/SciViews-K/templates/svSocket_0.9-41.tar.gz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: komodo/SciViews-K/templates/svSocket_0.9-41.tgz
===================================================================
(Binary files differ)
Property changes on: komodo/SciViews-K/templates/svSocket_0.9-41.tgz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: komodo/SciViews-K/templates/svSocket_0.9-41.zip
===================================================================
(Binary files differ)
Property changes on: komodo/SciViews-K/templates/svSocket_0.9-41.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: pkg/svMisc/R/descFun.R
===================================================================
--- pkg/svMisc/R/descFun.R (rev 0)
+++ pkg/svMisc/R/descFun.R 2008-07-07 01:38:43 UTC (rev 46)
@@ -0,0 +1,91 @@
+descFun <-
+function (fun, package, lib.loc = NULL) {
+ fun <- as.character(fun)
+ if (length(fun) == 0) return("")
+ # Get the description associated with this Topic
+ AllTopics <- eval(parse(text = paste("library(help =", package, ")")))$info[[2]]
+ if (length(AllTopics) == 0) return("")
+ res <- character()
+ for (i in 1:length(fun)) {
+ paths <- sapply(.find.package(package, lib.loc, verbose = FALSE),
+ function(p) index.search(fun[i], p, "AnIndex", type = "help"))
+ # Topic is the entry that contains the description
+ Topic <- basename(paths[paths != ""])[1]
+ # Get the first line of the description
+ FirstLine <- (1:length(AllTopics))[regexpr(paste("^", Topic, " ",
+ sep = ""), AllTopics) > -1]
+ # If not found, try with fun[i]
+ if (length(FirstLine) == 0) {
+ Topic <- fun[i]
+ FirstLine <- (1:length(AllTopics))[regexpr(paste("^", Topic, " ",
+ sep = ""), AllTopics) > -1]
+ }
+ if (length(FirstLine) == 0) {
+ res[i] <- "" # Not found (should never happen?)
+ } else {
+ # Eliminate everything before this line
+ Topics <- AllTopics[FirstLine[1]:length(AllTopics)]
+ # We may have several lines of description: keep them all
+ isSpace <- (regexpr("^ ", Topics) == -1)
+ isDesc <- (cumsum(isSpace) == 1)
+ Topics[1] <- sub(paste("^", Topic, sep = ""), "", Topics[1])
+ # Get the description and return it
+ res[i] <- paste(sub("^ +", "", Topics[isDesc]), collapse = " ")
+ }
+ }
+ # Add names to this vector and return it
+ names(res) <- fun
+ return(res)
+}
+
+descArgs <-
+function (fun, args = NULL, package = NULL, lib.loc = NULL) {
+ # Start from the text version of the online help instead of the .Rd file
+ if (is.null(package)) {
+ File <- as.character(help(fun,
+ lib.loc = lib.loc, chmhelp = FALSE, htmlhelp = FALSE))
+ } else {
+ File <- as.character(help(fun, package = parse(text = package),
+ lib.loc = lib.loc, chmhelp = FALSE, htmlhelp = FALSE))
+ }
+ if (length(File) == 0) return(rep("", length(args)))
+ # Read content of the text file
+ Data <- scan(File, what = character(), sep ="\n", quiet = TRUE)
+ # Get the Arguments: section
+ argsStart <- (1:length(Data))[Data == "_\bA_\br_\bg_\bu_\bm_\be_\bn_\bt_\bs:"]
+ if (length(argsStart) == 0) # Not found
+ return(rep("", length(args)))
+ # Eliminate everything before this section
+ Data <- Data[(argsStart[1] + 1):length(Data)]
+ # Check where next section starts
+ nextSection <- (1:length(Data))[regexpr("^_\\b", Data) > -1]
+ if (length(nextSection) > 0) # Cut everything after this section
+ Data <- Data[1:(nextSection[1] - 1)]
+ # Split description by arguments. Looks like: "^ *argument[, argument]: " + desc
+ argsFirstLine <- regexpr("^ *[a-zA-Z0-9_., ]+: .*$", Data) > -1
+ argsNames <- sub("^ *([a-zA-Z0-9_., ]+): .*$", "\\1", Data[argsFirstLine])
+ # Try to detect false argsNames, when ":" occurs in description
+ isArgs <- (regexpr("[^,] ", argsNames) == -1)
+ argsFirstLine[argsFirstLine] <- isArgs
+ argsNames <- argsNames[isArgs]
+ # Get the argument description
+ argsDesc <- sub("^ *(.*)$", "\\1", Data)
+ argsDesc[argsFirstLine] <- sub("^[a-zA-Z0-9_., ]+: (.*)$", "\\1",
+ argsDesc[argsFirstLine])
+ # Create a character vector with the successive argument descriptions
+ res <- tapply(argsDesc, cumsum(argsFirstLine), paste, collapse = " ")
+ res <- as.vector(res)
+ # Create multiple entries for "arg1, arg2, ..."
+ argsNames <- strsplit(argsNames, ", ")
+ Times <- sapply(argsNames, length)
+ res <- rep(res, Times)
+ names(res) <- unlist(argsNames)
+ # If args is not NULL, filter according to provided arguments
+ if (!is.null(args)) {
+ res <- res[as.character(args)]
+ # If arg names do not exists, return NA -> replace by ""
+ names(res) <- args
+ res[is.na(res)] <- ""
+ }
+ return(res)
+}
Added: pkg/svMisc/man/descFun.Rd
===================================================================
--- pkg/svMisc/man/descFun.Rd (rev 0)
+++ pkg/svMisc/man/descFun.Rd 2008-07-07 01:38:43 UTC (rev 46)
@@ -0,0 +1,48 @@
+\name{descFun}
+\alias{descFun}
+\alias{descArgs}
+
+\title{ Get textual help on function or function arguments }
+\description{
+ Textual help on functions or their arguments is extracted for text online help
+ for a given function. By default, all arguments from the online help are
+ returned for \code{descArgs()}. If the file contains help for several function,
+ one probably get also some irrelevant information. Use of 'args' to limit
+ result is strongly encouraged.
+}
+
+\usage{
+descFun(fun, package, lib.loc = NULL)
+descArgs(fun, args = NULL, package = NULL, lib.loc = NULL)
+}
+
+\arguments{
+ \item{fun}{ A character string with the name of a function (several
+ functions accepted for \code{descFun()} }
+ \item{args}{ Either \code{NULL} (by default) to return the description of all
+ arguments from the corresponding man page, or a character vector with names
+ of the arguments to search for }
+ \item{package}{ A character string with the name of the package that contains
+ \code{fun}, or \code{NULL} for searching in all loaded packages }
+ \item{lib.loc} { A character vector of directory names of \R libraries, or
+ \code{NULL}. The default value of \code{NULL} corresponds to all libraries
+ currently known. If the default is used, the loaded packages are searched
+ before the libraries. }
+}
+
+\value{
+ A string with the description of the function or of its arguments. If the man
+ page is not found, a vector of empty strings is returned. Empty strings are
+ also returned for arguments that are not found in the man page.
+}
+\author{ Philippe Grosjean <phgrosjean at sciviews.org> }
+
+\seealso{ \code{\link{CompletePlus}} }
+
+\examples{
+descFun("ls", "base")
+descFun("library", "base")
+descArgs("ls")
+descArgs("library", args = c("package", "pos"))
+}
+\keyword{ utilities }
Property changes on: pkg/svMisc/man/descFun.Rd
___________________________________________________________________
Name: svn:executable
+ *
More information about the Sciviews-commits
mailing list