我总是发现其他人的创业简介文件对这门语言既有用又有指导意义。此外,虽然我对Bash和Vim进行了一些定制,但对R没有任何定制。

例如,我一直想要的一件事是在窗口终端中输入和输出文本的颜色不同,甚至可能是语法高亮显示。


当前回答

下面是我发现的两个方便使用窗口的函数。

第一个将\s转换为/。

.repath <- function() {
   cat('Paste windows file path and hit RETURN twice')
   x <- scan(what = "")
   xa <- gsub('\\\\', '/', x)
   writeClipboard(paste(xa, collapse=" "))
   cat('Here\'s your de-windowsified path. (It\'s also on the clipboard.)\n', xa, '\n')
 }

第二个选项在一个新的资源管理器窗口中打开工作目录。

getw <- function() {
    suppressWarnings(shell(paste("explorer",  gsub('/', '\\\\', getwd()))))
}

其他回答

这是我的想法,包括上面提到的一些想法。

你可能需要看两件事:

.set.width() / w()将打印宽度更新为其中一个终端。不幸的是,我没有找到一种方法在终端调整大小上自动做到这一点- R文档提到这是由一些R解释器完成的。 每次都会保存历史记录,并保存时间戳和工作目录

.

.set.width <- function() {
  cols <- as.integer(Sys.getenv("COLUMNS"))
  if (is.na(cols) || cols > 10000 || cols < 10)
    options(width=100)
  options(width=cols)
}

.First <- function() {
  options(digits.secs=3)              # show sub-second time stamps
  options(max.print=1000)             # do not print more than 1000 lines
  options("report" = c(CRAN="http://cran.at.r-project.org"))
  options(prompt="R> ", digits=4, show.signif.stars=FALSE)
}

# aliases
w <- .set.width

.Last <- function() {
  if (!any(commandArgs()=='--no-readline') && interactive()){
    timestamp(,prefix=paste("##------ [",getwd(),"] ",sep=""))
    try(savehistory("~/.Rhistory"))
   }
}

下面是我发现的两个方便使用窗口的函数。

第一个将\s转换为/。

.repath <- function() {
   cat('Paste windows file path and hit RETURN twice')
   x <- scan(what = "")
   xa <- gsub('\\\\', '/', x)
   writeClipboard(paste(xa, collapse=" "))
   cat('Here\'s your de-windowsified path. (It\'s also on the clipboard.)\n', xa, '\n')
 }

第二个选项在一个新的资源管理器窗口中打开工作目录。

getw <- function() {
    suppressWarnings(shell(paste("explorer",  gsub('/', '\\\\', getwd()))))
}

我喜欢保存我的R命令历史,并在每次运行R命令时都可用:

在shell或.bashrc中:

export R_HISTFILE=~/.Rhistory

在.Rprofile:

.Last <- function() {
        if (!any(commandArgs()=='--no-readline') && interactive()){
                require(utils)
                try(savehistory(Sys.getenv("R_HISTFILE")))
        }
}

我有一个环境变量R_USER_WORKSPACE,它指向包的顶部目录。在. rprofile中,我定义了一个函数devlib,它设置了工作目录(以便data()工作),并在R子目录中获取所有.R文件。它与上面Hadley的l()函数非常相似。

devlib <- function(pkg) {
  setwd(file.path(Sys.getenv("R_USER_WORKSPACE", "."), deparse(substitute(pkg)), "dev"))
  sapply(list.files("R", pattern=".r$", ignore.case=TRUE, full.names=TRUE), source)
  invisible(NULL)
}

.First <- function() {
  setwd(Sys.getenv("R_USER_WORKSPACE", "."))
  options("repos" = c(CRAN = "http://mirrors.softliste.de/cran/", CRANextra="http://www.stats.ox.ac.uk/pub/RWin"))
}

.Last <- function() update.packages(ask="graphics")

我经常需要调用一系列调试调用,取消注释它们可能非常乏味。在SO社区的帮助下,我找到了以下解决方案,并将其插入到我的. rprofile .site中。# BROWSER是为我的Eclipse任务设置的,这样我就可以在任务视图窗口中对浏览器调用有一个概述。

# turn debugging on or off
# place "browser(expr = isTRUE(getOption("debug"))) # BROWSER" in your function
# and turn debugging on or off by bugon() or bugoff()
bugon <- function() options("debug" = TRUE)
bugoff <- function() options("debug" = FALSE) #pun intended