~ubuntu-branches/ubuntu/lucid/rcmdr/lucid-proposed

« back to all changes in this revision

Viewing changes to R/Rexcel-specific.R

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2008-04-10 16:33:09 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410163309-8ir2uhylr0bshcir
Tags: 1.3-14-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# These functions for Excel supportwritten by Erich Neuwirth
2
 
#  last modified: 22 June 2007 by J. Fox
3
 
 
4
 
    RExcelSupported <- function(){
5
 
        RExcelSupport <- getOption("Rcmdr")$RExcelSupport
6
 
        !is.null(RExcelSupport) && RExcelSupport && exists("RExcelEnv") &&
7
 
            exists("putRExcel", where="RExcelEnv")
8
 
        }
9
 
 
10
 
 
11
 
 
12
 
 
13
 
    SubmitToCommander <- function(commands){
14
 
        .log <- LogWindow()
15
 
        lines<-commands
16
 
        lines <- strsplit(lines, "\n")[[1]]
17
 
        .console.output <- getRcmdr("console.output")
18
 
        .output <- OutputWindow()
19
 
        iline <- 1
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=""))
26
 
            else{
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"))
30
 
                }
31
 
            jline <- iline + 1
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"))
35
 
                else{
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"))
39
 
                    }
40
 
                current.line <- paste(current.line, lines[jline],sep="\n")
41
 
                jline <- jline + 1
42
 
                iline <- iline + 1
43
 
                }
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)
48
 
                }
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)
53
 
                }
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)
58
 
                }
59
 
            else if (length(current.line)>0) {
60
 
                          doItAndPrint(current.line, log=FALSE)
61
 
                loggerForExcel(current.line)
62
 
                          }
63
 
            }
64
 
            iline <- iline + 1
65
 
        }
66
 
    tkyview.moveto(.output, 1)
67
 
    }
68
 
 
69
 
 
70
 
 
71
 
 
72
 
loggerForExcel <- function(command){
73
 
    if (is.SciViews()) return(svlogger(command))    # +PhG
74
 
    .log <- LogWindow()
75
 
    .output <- OutputWindow()
76
 
    if (getRcmdr("log.commands")) {
77
 
        tkinsert(.log, "end", paste(command,"\n", sep=""))
78
 
        tkyview.moveto(.log, 1)
79
 
        }
80
 
    }
81
 
 
 
1
# These functions for Excel supportwritten by Erich Neuwirth
 
2
#  last modified: 20 March 2008 by J. Fox  (following instructions from Erich Neuwirth)
 
3
 
 
4
    RExcelSupported <- function(){
 
5
        RExcelSupport <- getOption("Rcmdr")$RExcelSupport
 
6
        !is.null(RExcelSupport) && RExcelSupport && exists("RExcelEnv") &&
 
7
            exists("putRExcel", where="RExcelEnv")
 
8
        }
 
9
 
 
10
 
 
11
 
 
12
 
 
13
    SubmitToCommander <- function(commands){
 
14
        .log <- LogWindow()
 
15
        lines<-commands
 
16
        lines <- strsplit(lines, "\n")[[1]]
 
17
        .console.output <- getRcmdr("console.output")
 
18
        .output <- OutputWindow()
 
19
        iline <- 1
 
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=""))
 
26
            else{
 
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"))
 
30
                }
 
31
            jline <- iline + 1
 
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"))
 
35
                else{
 
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"))
 
39
                    }
 
40
                current.line <- paste(current.line, lines[jline],sep="\n")
 
41
                jline <- jline + 1
 
42
                iline <- iline + 1
 
43
                }
 
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)
 
48
                }
 
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)
 
53
                }
 
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)
 
58
##                }
 
59
            else if (length(current.line)>0) {
 
60
                          doItAndPrint(current.line, log=FALSE)
 
61
                loggerForExcel(current.line)
 
62
                          }
 
63
            }
 
64
            iline <- iline + 1
 
65
        }
 
66
    tkyview.moveto(.output, 1)
 
67
    }
 
68
 
 
69
 
 
70
 
 
71
 
 
72
loggerForExcel <- function(command){
 
73
    if (is.SciViews()) return(svlogger(command))    # +PhG
 
74
    .log <- LogWindow()
 
75
    .output <- OutputWindow()
 
76
    if (getRcmdr("log.commands")) {
 
77
        tkinsert(.log, "end", paste(command,"\n", sep=""))
 
78
        tkyview.moveto(.log, 1)
 
79
        }
 
80
    }
 
81