我总是发现其他人的创业简介文件对这门语言既有用又有指导意义。此外,虽然我对Bash和Vim进行了一些定制,但对R没有任何定制。
例如,我一直想要的一件事是在窗口终端中输入和输出文本的颜色不同,甚至可能是语法高亮显示。
我总是发现其他人的创业简介文件对这门语言既有用又有指导意义。此外,虽然我对Bash和Vim进行了一些定制,但对R没有任何定制。
例如,我一直想要的一件事是在窗口终端中输入和输出文本的颜色不同,甚至可能是语法高亮显示。
当前回答
下面是将表导出到LaTeX的一小段代码。它将我编写的许多报告的所有列名更改为数学模式。我的. r配置文件的其余部分是相当标准的,上面已经介绍了大部分内容。
# Puts $dollar signs in front and behind all column names col_{sub} -> $col_{sub}$
amscols<-function(x){
colnames(x) <- paste("$", colnames(x), "$", sep = "")
x
}
其他回答
这是我的。没什么太创新的。为什么要选择特定的选项:
I went with setting a default for stringsAsFactors because I find it extremely draining to pass it as an argument each time I read a CSV in. That said, it has already caused me some minor vexation when using code written on my usual computer on a computer which did not have my .Rprofile. I'm keeping it, though, as the troubles it has caused pale in comparison to the troubles not having it set everyday used to cause. If you don't load the utils package before options(error=recover), it cannot find recover when placed inside an interactive() block. I used .db for my dropbox setting rather than options(dropbox=...) because I use it all the time inside file.path and it saves much typing. The leading . keeps it from appearing with ls().
话不多说:
if(interactive()) {
options(stringsAsFactors=FALSE)
options(max.print=50)
options(repos="http://cran.mirrors.hoobly.com")
}
.db <- "~/Dropbox"
# `=` <- function(...) stop("Assignment by = disabled, use <- instead")
options(BingMapsKey="blahblahblah") # Used by taRifx.geo::geocode()
.First <- function() {
if(interactive()) {
require(functional)
require(taRifx)
require(taRifx.geo)
require(ggplot2)
require(foreign)
require(R.utils)
require(stringr)
require(reshape2)
require(devtools)
require(codetools)
require(testthat)
require(utils)
options(error=recover)
}
}
这是我的。我总是使用主要的cran存储库,并且有代码可以使它很容易地获得开发包中的代码。
.First <- function() {
library(graphics)
options("repos" = c(CRAN = "http://cran.r-project.org/"))
options("device" = "quartz")
}
packages <- list(
"describedisplay" = "~/ggobi/describedisplay",
"linval" = "~/ggobi/linval",
"ggplot2" = "~/documents/ggplot/ggplot",
"qtpaint" = "~/documents/cranvas/qtpaint",
"tourr" = "~/documents/tour/tourr",
"tourrgui" = "~/documents/tour/tourr-gui",
"prodplot" = "~/documents/categorical-grammar"
)
l <- function(pkg) {
pkg <- tolower(deparse(substitute(pkg)))
if (is.null(packages[[pkg]])) {
path <- file.path("~/documents", pkg, pkg)
} else {
path <- packages[pkg]
}
source(file.path(path, "load.r"))
}
test <- function(path) {
path <- deparse(substitute(path))
source(file.path("~/documents", path, path, "test.r"))
}
我发现两个函数是非常必要的:首先,当我在几个函数上设置debug()并且我已经解决了错误,所以我想要undebug()所有函数-而不是一个接一个。在这里添加的undebug_all()函数作为接受的答案是最好的。
其次,当我定义了许多函数并正在寻找一个特定的变量名时,很难在ls()的所有结果中找到它,包括函数名。这里发布的lsnofun()函数真的很好。
我经常需要调用一系列调试调用,取消注释它们可能非常乏味。在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
我的不太花哨:
# So the mac gui can find latex
Sys.setenv("PATH" = paste(Sys.getenv("PATH"),"/usr/texbin",sep=":"))
#Use last(x) instead of x[length(x)], works on matrices too
last <- function(x) { tail(x, n = 1) }
#For tikzDevice caching
options( tikzMetricsDictionary='/Users/cameron/.tikzMetricsDictionary' )