Expert r użytkowników, co jest w Twoim.Rprofile? [zamknięte]

Obecnie pytanie to nie pasuje do naszego formatu pytań i odpowiedzi. Oczekujemy, że odpowiedzi będą poparte faktami, referencjami lub wiedzą specjalistyczną, ale to pytanie będzie prawdopodobnie wywoływało debatę, argumenty, ankiety lub rozszerzoną dyskusję. Jeśli uważasz, że to pytanie można poprawić i ewentualnie ponownie otworzyć, odwiedź Pomoc centrum dla wskazówek. Zamknięte 8 lat temu .

Zawsze znajdowałem pliki profilu startowego innych osób, zarówno przydatne, jak i pouczające o języku. Co więcej, chociaż mam pewne modyfikacje dla Bash i Vim , nie mam nic dla R.

Na przykład zawsze chciałem mieć różne kolory tekstu wejściowego i wyjściowego w oknie terminal, a może nawet podświetlanie składni.

Author: Peter Mortensen, 2009-07-27

24 answers

Tutaj jest mój. Nie pomoże Ci to w kolorowaniu, ale mam to z ESS i Emacsa...

options("width"=160)                # wide display with multiple monitors
options("digits.secs"=3)            # show sub-second time stamps

r <- getOption("repos")             # hard code the US repo for CRAN
r["CRAN"] <- "http://cran.us.r-project.org"
options(repos = r)
rm(r)

## put something this is your .Rprofile to customize the defaults
setHook(packageEvent("grDevices", "onLoad"),
        function(...) grDevices::X11.options(width=8, height=8, 
                                             xpos=0, pointsize=10, 
                                             #type="nbcairo"))  # Cairo device
                                             #type="cairo"))    # other Cairo dev
                                             type="xlib"))      # old default

## from the AER book by Zeileis and Kleiber
options(prompt="R> ", digits=4, show.signif.stars=FALSE)


options("pdfviewer"="okular")         # on Linux, use okular as the pdf viewer
 96
Author: Dirk Eddelbuettel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-07-22 03:12:04
options(stringsAsFactors=FALSE)
Chociaż nie mam tego w swoim .Rprofile, bo może złamać kod moich współautorów, szkoda, że nie jest to domyślne. Dlaczego?

1) wektory znaków zużywają mniej pamięci (ale tylko ledwie);

2) co ważniejsze, unikniemy problemów takich jak:

> x <- factor(c("a","b","c"))
> x
[1] a b c
Levels: a b c
> x <- c(x, "d")
> x
[1] "1" "2" "3" "d"

I

> x <- factor(c("a","b","c"))
> x[1:2] <- c("c", "d")
Warning message:
In `[<-.factor`(`*tmp*`, 1:2, value = c("c", "d")) :
  invalid factor level, NAs generated

Czynniki są świetne, gdy ich potrzebujesz (np. implementacja kolejności w wykresach), ale przez większość czasu są uciążliwe.

 59
Author: Eduardo Leoni,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-09 01:26:01

Nienawidzę wpisywać pełnych słów 'Głowa', 'podsumowanie', 'nazwy' za każdym razem, więc używam aliasów.

Możesz umieścić aliasy w swoim .Plik Rprofile, ale musisz użyć pełnej ścieżki do funkcji (np. utils:: head) w przeciwnym razie nie będzie działać.

# aliases
s <- base::summary
h <- utils::head
n <- base::names

EDIT: aby odpowiedzieć na twoje pytanie, możesz użyć pakietu colorout , aby mieć różne kolory w terminalu. Super! :-)

 59
Author: dalloliogm,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-03-06 11:43:17

Lubię zapisywać historię poleceń R i mieć ją dostępną za każdym razem, gdy uruchamiam R:

W muszli lub .bashrc:

export R_HISTFILE=~/.Rhistory

W .Rprofile:

.Last <- function() {
        if (!any(commandArgs()=='--no-readline') && interactive()){
                require(utils)
                try(savehistory(Sys.getenv("R_HISTFILE")))
        }
}
 27
Author: Jeff,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-02 03:05:25

To moje. Zawsze używam głównego repozytorium cran i mam kod, aby ułatwić źródło kodu pakietu w fazie rozwoju.

.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"))  
}
 26
Author: hadley,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-07-28 04:34:51

Oto dwie funkcje, które przydają mi się do pracy z systemem windows.

Pierwszy zamienia \ na /.

.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')
 }

Drugi otwiera katalog roboczy w nowym oknie Eksploratora.

getw <- function() {
    suppressWarnings(shell(paste("explorer",  gsub('/', '\\\\', getwd()))))
}
 25
Author: Tom,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-03 07:38:14

Mam taki, bardziej dynamiczny trick, aby używać pełnej szerokości terminala, który próbuje odczytać ze zmiennej środowiskowej COLUMNS (na Linuksie):

tryCatch(
  {options(
      width = as.integer(Sys.getenv("COLUMNS")))},
  error = function(err) {
    write("Can't get your terminal width. Put ``export COLUMNS'' in your \
           .bashrc. Or something. Setting width to 120 chars",
           stderr());
    options(width=120)}
)

W ten sposób R użyje pełnej szerokości, nawet gdy zmienisz rozmiar okna terminala.

 18
Author: Branimir Dolicki,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-07-29 10:00:54

Większość moich osobistych funkcji i załadowanych bibliotek znajduje się w Rfunctions.R script

source("c:\\data\\rprojects\\functions\\Rfunctions.r")


.First <- function(){
   cat("\n Rrrr! The statistics program for Pirates !\n\n")

  }

  .Last <- function(){
   cat("\n Rrrr! Avast Ye, YO HO!\n\n")

  }


#===============================================================
# Tinn-R: necessary packages
#===============================================================
library(utils)
necessary = c('svIDE', 'svIO', 'svSocket', 'R2HTML')
if(!all(necessary %in% installed.packages()[, 'Package']))
  install.packages(c('SciViews', 'R2HTML'), dep = T)

options(IDE = 'C:/Tinn-R/bin/Tinn-R.exe')
options(use.DDE = T)

library(svIDE)
library(svIO)
library(svSocket)
library(R2HTML)
guiDDEInstall()
shell(paste("mkdir C:\\data\\rplots\\plottemp", gsub('-','',Sys.Date()), sep=""))
pldir <- paste("C:\\data\\rplots\\plottemp", gsub('-','',Sys.Date()), sep="")

plot.str <-c('savePlot(paste(pldir,script,"\\BeachSurveyFreq.pdf",sep=""),type="pdf")')
 17
Author: kpierce8,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-07-27 21:54:20

Oto z mojego ~/.Rprofile , przeznaczony dla komputerów Mac i Linux.

To sprawia, że błędy są łatwiejsze do zauważenia.
options(showWarnCalls=T, showErrorCalls=T)
Nienawidzę wyboru menu CRAN, więc ustaw na dobre.
options(repos=c("http://cran.cnr.Berkeley.edu","http://cran.stat.ucla.edu"))
Więcej historii!
Sys.setenv(R_HISTSIZE='100000')

Poniżej jest do uruchomienia na Mac OSX z terminala (który zdecydowanie wolę R. app, ponieważ jest bardziej stabilny, i można zorganizować pracę według katalogu; również upewnij się, aby uzyskać dobry ~/.inputrc ). Domyślnie wyświetlany jest Wyświetlacz X11, co nie wygląda tak ładnie; to zamiast tego daje wyświetlacz kwarcowy taki sam jak GUI. Instrukcja if ma przechwytywać sprawę, gdy uruchamiasz R z terminala na Macu.

f = pipe("uname")
if (.Platform$GUI == "X11" && readLines(f)=="Darwin") {
  # http://www.rforge.net/CarbonEL/
  library("grDevices")
  library("CarbonEL")
  options(device='quartz')
  Sys.unsetenv("DISPLAY")
}
close(f); rm(f)

I wstępnie załadować kilka bibliotek,

library(plyr)
library(stringr)
library(RColorBrewer)
if (file.exists("~/util.r")) {
  source("~/util.r")
}

Gdzie util.r jest przypadkowym workiem rzeczy, których używam, pod flux.

Również, ponieważ inni ludzie wspominali o szerokości konsoli, oto jak to zrobić.

if ( (numcol <-Sys.getenv("COLUMNS")) != "") {
  numcol = as.integer(numcol)
  options(width= numcol - 1)
} else if (system("stty -a &>/dev/null") == 0) {
  # mac specific?  probably bad in the R GUI too.
  numcol = as.integer(sub(".* ([0-9]+) column.*", "\\1", system("stty -a", intern=T)[1]))
  if (numcol > 0)
    options(width=  numcol - 1 )
}
rm(numcol)

To właściwie nie jest w .Rprofile ponieważ musisz go ponownie uruchomić za każdym razem, gdy Zmień rozmiar okna terminala. Mam go w util.r, więc po prostu źródła go w razie potrzeby.

 17
Author: Brendan OConnor,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-08-19 20:43:33

Oto moje:

.First <- function () {
  options(device="quartz")
}

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

# Slightly more flexible than as.Date
# my.as.Date("2009-01-01") == my.as.Date(2009, 1, 1) == as.Date("2009-01-01")
my.as.Date <- function (a, b=NULL, c=NULL, ...) {
  if (class(a) != "character")
    return (as.Date(sprintf("%d-%02d-%02d", a, b, c)))
  else
    return (as.Date(a))
}

# Some useful aliases
cd <- setwd
pwd <- getwd
lss <- dir
asd <- my.as.Date # examples: asd("2009-01-01") == asd(2009, 1, 1) == as.Date("2009-01-01")
last <- function (x, n=1, ...) tail(x, n=n, ...)

# Set proxy for all web requests
Sys.setenv(http_proxy="http://192.168.0.200:80/")

# Search RPATH for file <fn>.  If found, return full path to it
search.path <- function(fn,
     paths = strsplit(chartr("\\", "/", Sys.getenv("RPATH")), split =
                switch(.Platform$OS.type, windows = ";", ":"))[[1]]) {
  for(d in paths)
     if (file.exists(f <- file.path(d, fn)))
        return(f)
  return(NULL)
}

# If loading in an environment that doesn't respect my RPATH environment
# variable, set it here
if (Sys.getenv("RPATH") == "") {
  Sys.setenv(RPATH=file.path(path.expand("~"), "Library", "R", "source"))
}

# Load commonly used functions
if (interactive())
  source(search.path("afazio.r"))

# If no R_HISTFILE environment variable, set default
if (Sys.getenv("R_HISTFILE") == "") {
  Sys.setenv(R_HISTFILE=file.path("~", ".Rhistory"))
}

# Override q() to not save by default.
# Same as saying q("no")
q <- function (save="no", ...) {
  quit(save=save, ...)
}

# ---------- My Environments ----------
#
# Rather than starting R from within different directories, I prefer to
# switch my "environment" easily with these functions.  An "environment" is
# simply a directory that contains analysis of a particular topic.
# Example usage:
# > load.env("markets")  # Load US equity markets analysis environment
# > # ... edit some .r files in my environment
# > reload()             # Re-source .r/.R files in my environment
#
# On next startup of R, I will automatically be placed into the last
# environment I entered

# My current environment
.curr.env = NULL

# File contains name of the last environment I entered
.last.env.file = file.path(path.expand("~"), ".Rlastenv")

# Parent directory where all of my "environment"s are contained
.parent.env.dir = file.path(path.expand("~"), "Analysis")

# Create parent directory if it doesn't already exist
if (!file.exists(.parent.env.dir))
  dir.create(.parent.env.dir)

load.env <- function (string, save=TRUE) {
  # Load all .r/.R files in <.parent.env.dir>/<string>/
  cd(file.path(.parent.env.dir, string))
  for (file in lss()) {
    if (substr(file, nchar(file)-1, nchar(file)+1) %in% c(".r", ".R"))
      source(file)
  }
  .curr.env <<- string
  # Save current environment name to file
  if (save == TRUE) writeLines(.curr.env, .last.env.file)
  # Let user know environment switch was successful
  print (paste(" -- in ", string, " environment -- "))
}

# "reload" current environment.
reload <- resource <- function () {
  if (!is.null(.curr.env))
    load.env(.curr.env, save=FALSE)
  else
    print (" -- not in environment -- ")
}

# On startup, go straight to the environment I was last working in
if (interactive() && file.exists(.last.env.file)) {
  load.env(readLines(.last.env.file))
}
 16
Author: Alfred J Fazio,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-16 21:23:06
sink(file = 'R.log', split=T)

options(scipen=5)

.ls.objects <- function (pos = 1, pattern, order.by = "Size", decreasing=TRUE, head =     TRUE, n = 10) {
  # based on postings by Petr Pikal and David Hinds to the r-help list in 2004
  # modified by: Dirk Eddelbuettel (http://stackoverflow.com/questions/1358003/tricks-to-    manage-the-available-memory-in-an-r-session) 
  # I then gave it a few tweaks (show size as megabytes and use defaults that I like)
  # a data frame of the objects and their associated storage needs.
  napply <- function(names, fn) sapply(names, function(x)
          fn(get(x, pos = pos)))
  names <- ls(pos = pos, pattern = pattern)
  obj.class <- napply(names, function(x) as.character(class(x))[1])
  obj.mode <- napply(names, mode)
  obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class)
  obj.size <- napply(names, object.size) / 10^6 # megabytes
  obj.dim <- t(napply(names, function(x)
            as.numeric(dim(x))[1:2]))
  vec <- is.na(obj.dim)[, 1] & (obj.type != "function")
  obj.dim[vec, 1] <- napply(names, length)[vec]
  out <- data.frame(obj.type, obj.size, obj.dim)
  names(out) <- c("Type", "Size", "Rows", "Columns")
  out <- out[order(out[[order.by]], decreasing=decreasing), ]
  if (head)
    out <- head(out, n)
  out
}
 11
Author: Patrick McCann,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-02-09 22:11:51

Twórz dane.ramki wyświetlają się nieco jak 'head', tylko bez konieczności wpisywania 'head'

print.data.frame <- function(df) {
   if (nrow(df) > 10) {
      base::print.data.frame(head(df, 5))
      cat("----\n")
      base::print.data.frame(tail(df, 5))
   } else {
      base::print.data.frame(df)
   }
}

(z Jak sprawić, by' head ' został automatycznie zastosowany do wyjścia? )

 11
Author: Hugh Perkins,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:25:37

Często mam łańcuch wywołań debugowania, które muszę wywołać, a ich nieuwzględnianie może być bardzo uciążliwe. Z pomocą so community, poszedłem po następujące rozwiązanie i wstawiłem to do mojego .Rprofile.site. # BROWSER jest tam dla moich zadań Eclipse tak, że mam przegląd wywołań przeglądarki w oknie widoku zadania.

# 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
 10
Author: Roman Luštrik,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:17:29

Mój nie jest zbyt fantazyjny:

# 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' )
 9
Author: cameron.bracken,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-07-30 18:30:58
setwd("C://path//to//my//prefered//working//directory")
library("ggplot2")
library("RMySQL")
library("foreign")
answer <- readline("What database would you like to connect to? ")
con <- dbConnect(MySQL(),user="root",password="mypass", dbname=answer)

Wykonuję dużo pracy z baz danych mysql, więc łączenie się od razu jest darem niebios. Szkoda tylko, że nie ma sposobu na wymienienie dostępnych baz danych, żebym nie musiał pamiętać wszystkich różnych nazw.

 8
Author: Brandon Bertelsen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-07-26 06:35:42

Stephen Turner ' s post on .Rprofiles ma kilka przydatnych aliasów i funkcji startowych.

Często używam jego ht i hh.
#ht==headtail, i.e., show the first and last 10 items of an object
ht <- function(d) rbind(head(d,10),tail(d,10))

# Show the first 5 rows and first 5 columns of a data frame or matrix
hh <- function(d) d[1:5,1:5]
 8
Author: Ram Narasimhan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-12-30 04:08:54

Oto moje, w tym niektóre z wymienionych pomysłów.

Dwie rzeczy, na które warto spojrzeć:

  • .gotowi.szerokość() / w() zaktualizuje szerokość wydruku do szerokości terminala. Niestety nie znalazłem sposobu, aby zrobić to automatycznie w dokumentacji terminal resize-R wspomina, że robi to niektóre interpretery R.
  • historia jest zapisywana za każdym razem wraz ze znacznikiem czasu i katalogiem roboczym

.

.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"))
   }
}
 7
Author: Florian Bw,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-12-14 12:35:11

Używam poniższego, aby uzyskać cacheSweave (lub pgfSweave) do pracy z przyciskiem "Skompiluj PDF" w RStudio:

library(cacheSweave)
assignInNamespace("RweaveLatex", cacheSweave::cacheSweaveDriver, "utils")
 7
Author: ROLO,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-10-21 13:58:34

Mój zawiera options(menu.graphics=FALSE) ponieważ lubię wyłączyć/wyłączyć tcltk popup dla wyboru lustra Cran w R.

 7
Author: isomorphismes,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:17:29

Oto mój. Nic innowacyjnego. Myśli o tym, dlaczego poszczególne wybory:

  • wybrałem ustawienie domyślne dla stringsAsFactors ponieważ znajduję to bardzo wyczerpujące, aby przekazać go jako argument za każdym razem, gdy czytam CSV w. To powiedziawszy, to już spowodowało mi jakieś drobne irytacje podczas używania kodu napisanego na moim zwykłym komputerze na komputerze, który nie miał mojego .Rprofile. Zatrzymuję go jednak, ponieważ problemy, które spowodował BLADE w porównaniu do kłopotów, nie mając go ustawione codziennie kiedyś powodował.
  • Jeśli nie załadujesz pakietu utils przed options(error=recover), nie może on znaleźć odzyskiwania po umieszczeniu w bloku interactive().
  • użyłem .db dla mojego ustawienia dropbox zamiast options(dropbox=...), ponieważ używam go cały czas wewnątrz file.path i oszczędza to wiele pisania. Czołówka . zapobiega pojawianiu się z ls().

Bez zbędnych ceregieli:

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)
    }
}
 7
Author: Ari B. Friedman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-23 12:19:41

Oto mały fragment do wykorzystania w eksporcie tabel do LaTeX. Zmienia wszystkie nazwy kolumn na tryb matematyczny dla wielu raportów, które piszę. Reszta moich .Rprofile jest dość standardowe i w większości pokryte powyżej.

# Puts $dollar signs in front and behind all column names col_{sub} -> $col_{sub}$

amscols<-function(x){
    colnames(x) <- paste("$", colnames(x), "$", sep = "")
    x
}
 7
Author: N8TRO,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-16 21:25:02

Ustawiłem Mój motyw koloru kratki w moim profilu. Oto dwa inne poprawki, których używam:

# Display working directory in the titlebar
# Note: This causes demo(graphics) to fail
utils::setWindowTitle(base::getwd())
utils::assignInNamespace("setwd",function(dir)   {.Internal(setwd(dir));setWindowTitle(base::getwd())},"base")

# Don't print more than 1000 lines
options(max.print=2000)
 5
Author: Kevin Wright,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-08-12 15:55:15

Mam zmienną środowiskową R_USER_WORKSPACE, która wskazuje na górny katalog moich pakietów. Do środka .RPROFILE definiuję funkcję devlib, która ustawia katalog roboczy (tak, że działa data ()) i wszystkie źródła.Pliki R w podkatalogu r. Jest ona bardzo podobna do funkcji L() Hadleya powyżej.

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")
 5
Author: Karsten W.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-04-03 18:35:14

Znalazłem dwie funkcje naprawdę niezbędne: po pierwsze, gdy ustawiłem {[0] } Na kilku funkcjach i rozwiązałem błąd, więc chcę undebug() wszystkie funkcje - nie jedna po drugiej. Funkcja undebug_all() dodana jako akceptowana ODPOWIEDŹ tutaj jest najlepsza.

Po drugie, kiedy zdefiniowałem wiele funkcji i szukam konkretnej nazwy zmiennej, trudno jest znaleźć ją we wszystkich wynikach ls(), łącznie z nazwami funkcji. Funkcja lsnofun() zamieszczona tutaj jest naprawdę dobrze.

 5
Author: Ali,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:32:23