[R] some related problems

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Nov 12 16:57:25 CET 1999


> From: "Jens Oehlschlägel-Akiyoshi" <jens.oehlschlaegel-akiyoshi at mdfactory.de>
> Date: Fri, 12 Nov 1999 15:52:03 +0100
> 
> I just tried to batch-start rgui.exe (not rterm.exe) in a way, that it
> read.table()s data from a file with changing filename. As I understand no
> command line parameters are available for that, so instead I tried to pass
> the filename to an approbriate .RProfile, which works roughly, BUT
> 
> ## this is my %R_USER%\.RProfile
> im <- read.table("d:/temp/im/temp.csv", header=TRUE, sep=",")
> nam <- names(im)
> nnam <- nchar(nam)
> newnam <- substr(nam, 2, nnam-1) # change names from e.g. <"x"> to <x>
> names(im) <- newnam
> pairs2(im)
> ## end
> 
> Two lines in this code do not work *during* .RProfile execution, but they
> work if entered manually *after* all profile executions:
> 
> names(im) <- newnam  # should work always
> Error: attempt to set an attribute on NULL
> 
> pairs2(im) # my global RProfile sources a file which defines pairs2()
> Error: couldn't find function "pairs2"
> 
> How can I make these commands working during .RProfile execution?

I would not try. Define a .First function in the .Rprofile: that is run
later in the execution sequence.  Having said that, I don't fully
understand why your example does not work, but I suspect this is because
the code is failing to do what you expect and at that point the error
handlier is not running.  If there is an error in the Rprofiles, it
`drops through to further processing'.


BTW, it is .Rprofile, not .RProfile, but NT can't tell the difference.

> Moreover: how can I exchange single Backslashes to slashes in R?
> 
> I tried:
> 
> > gsub("[\\]", "/", "c:\temp")
> [1] "c:     emp"
> > gsub("[\\]", "/", "c:\\temp")
> [1] "c:/temp"
> 

You need to quote the quotes (look in help() on a Windows version for examples)

> gsub("\\\\", "/", "c:\\temp")
[1] "c:/temp"

which passes \\ to the regex code, and that substitutes for \


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list