1
# These functions for Excel supportwritten by Erich Neuwirth
2
# last modified: 22 June 2007 by J. Fox
4
RExcelSupported <- function(){
5
RExcelSupport <- getOption("Rcmdr")$RExcelSupport
6
!is.null(RExcelSupport) && RExcelSupport && exists("RExcelEnv") &&
7
exists("putRExcel", where="RExcelEnv")
13
SubmitToCommander <- function(commands){
16
lines <- strsplit(lines, "\n")[[1]]
17
.console.output <- getRcmdr("console.output")
18
.output <- OutputWindow()
20
nlines <- length(lines)
21
while (iline <= nlines){
22
while (whitespaceonly(lines[iline])) iline <- iline + 1
23
if (iline > nlines) break
24
current.line <- lines[iline]
25
if (.console.output) cat(paste("\nRcmdr> ", current.line,"\n", sep=""))
27
tkinsert(.output, "end", paste("\n> ", current.line,"\n", sep=""))
28
tktag.add(.output, "currentLine", "end - 2 lines linestart", "end - 2 lines lineend")
29
tktag.configure(.output, "currentLine", foreground=getRcmdr("command.text.color"))
32
while (jline <= nlines){
33
if (class(try(parse(text=current.line),silent=TRUE))!="try-error") break
34
if (.console.output)cat(paste("Rcmdr+ ", lines[jline], sep="\n"))
36
tkinsert(.output, "end", paste("+ ", lines[jline],"\n", sep=""))
37
tktag.add(.output, "currentLine", "end - 2 lines linestart", "end - 2 lines lineend")
38
tktag.configure(.output, "currentLine", foreground=getRcmdr("command.text.color"))
40
current.line <- paste(current.line, lines[jline],sep="\n")
44
if (!(is.null(current.line) || is.na(current.line))){
45
if (length(grep("<-", current.line)) > 0){
46
justDoIt(current.line)
47
loggerForExcel(current.line)
49
else if (length(grep("^remove\\(", current.line)) > 0){
50
current.line <- sub(")", ", envir=.GlobalEnv)", current.line)
51
justDoIt(current.line)
52
loggerForExcel(current.print.line)
54
else if (any(sapply(Commander.Input.exceptions,
55
function(.x) length(grep(paste("^", .x, "\\(", sep=""), current.line)) > 0))){
56
justDoIt(current.line)
57
loggerForExcel(current.line)
59
else if (length(current.line)>0) {
60
doItAndPrint(current.line, log=FALSE)
61
loggerForExcel(current.line)
66
tkyview.moveto(.output, 1)
72
loggerForExcel <- function(command){
73
if (is.SciViews()) return(svlogger(command)) # +PhG
75
.output <- OutputWindow()
76
if (getRcmdr("log.commands")) {
77
tkinsert(.log, "end", paste(command,"\n", sep=""))
78
tkyview.moveto(.log, 1)
1
# These functions for Excel supportwritten by Erich Neuwirth
2
# last modified: 20 March 2008 by J. Fox (following instructions from Erich Neuwirth)
4
RExcelSupported <- function(){
5
RExcelSupport <- getOption("Rcmdr")$RExcelSupport
6
!is.null(RExcelSupport) && RExcelSupport && exists("RExcelEnv") &&
7
exists("putRExcel", where="RExcelEnv")
13
SubmitToCommander <- function(commands){
16
lines <- strsplit(lines, "\n")[[1]]
17
.console.output <- getRcmdr("console.output")
18
.output <- OutputWindow()
20
nlines <- length(lines)
21
while (iline <= nlines){
22
while (whitespaceonly(lines[iline])) iline <- iline + 1
23
if (iline > nlines) break
24
current.line <- lines[iline]
25
if (.console.output) cat(paste("\nRcmdr> ", current.line,"\n", sep=""))
27
tkinsert(.output, "end", paste("\n> ", current.line,"\n", sep=""))
28
tktag.add(.output, "currentLine", "end - 2 lines linestart", "end - 2 lines lineend")
29
tktag.configure(.output, "currentLine", foreground=getRcmdr("command.text.color"))
32
while (jline <= nlines){
33
if (class(try(parse(text=current.line),silent=TRUE))!="try-error") break
34
if (.console.output)cat(paste("Rcmdr+ ", lines[jline], sep="\n"))
36
tkinsert(.output, "end", paste("+ ", lines[jline],"\n", sep=""))
37
tktag.add(.output, "currentLine", "end - 2 lines linestart", "end - 2 lines lineend")
38
tktag.configure(.output, "currentLine", foreground=getRcmdr("command.text.color"))
40
current.line <- paste(current.line, lines[jline],sep="\n")
44
if (!(is.null(current.line) || is.na(current.line))){
45
if (length(grep("<-", current.line)) > 0){
46
justDoIt(current.line)
47
loggerForExcel(current.line)
49
else if (length(grep("^remove\\(", current.line)) > 0){
50
current.line <- sub(")", ", envir=.GlobalEnv)", current.line)
51
justDoIt(current.line)
52
loggerForExcel(current.print.line)
54
## else if (any(sapply(Commander.Input.exceptions,
55
## function(.x) length(grep(paste("^", .x, "\\(", sep=""), current.line)) > 0))){
56
## justDoIt(current.line)
57
## loggerForExcel(current.line)
59
else if (length(current.line)>0) {
60
doItAndPrint(current.line, log=FALSE)
61
loggerForExcel(current.line)
66
tkyview.moveto(.output, 1)
72
loggerForExcel <- function(command){
73
if (is.SciViews()) return(svlogger(command)) # +PhG
75
.output <- OutputWindow()
76
if (getRcmdr("log.commands")) {
77
tkinsert(.log, "end", paste(command,"\n", sep=""))
78
tkyview.moveto(.log, 1)