[R] Path to R script
chuck at sharpsteen.net
Thu May 13 00:38:09 CEST 2010
Johannes W. Dietrich wrote:
> There is certainly a trivial solution for my question, but I can't
> find the answer in the documentation.
> I need a platform independent method to obtain the file path of the
> current R script.
> My working group uses R on several machines with different operating
> systems including Mac OS X, Windows and Linux, and for obvious
> reasons the file hierarchies are very different. Therefore, it would
> be useful to be able to address data files and external procedures
> relative to the path of the script.
> Thank you for any suggestion,
> J. W. D.
The best recipie I have for dealing with this situation is:
1. Place R scripts in a package (a very good idea anyway if you are
distributing code to others).
2. Place a configuration file in the package that contains info such as
paths to data directories.
3. Customize the configuration file after installing the package (if
Then your script accesses the configuration file, which is in a known fixed
location, and uses the information inside to find other files that may be in
unknown and changing locations.
You could also place the configuration file in a location such as:
path.expand( '~/' )
Has a pretty predictable behavior across platforms. This would save it from
being overwritten every time you updated the package.
Hope this helps!
Undergraduate-- Environmental Resources Engineering
Humboldt State University
View this message in context: http://r.789695.n4.nabble.com/Path-to-R-script-tp2196648p2196929.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help