Using R in multiple environments

This is just a quick post, with a neat little trick.

I use Linux (Ubuntu) at home and Windows in the lab, which can be frustrating for coding in R since I like to keep my work in nicely sorted working directories. I used to have to have two ‘setwd’ commands at the head of every R file, one for Windows and one for linux, and I would just accept that I’d get an error thrown. No big deal.

No more!

Check this out:

ifelse(.Platform$OS.type=='unix',
setwd('/home/simon/Dropbox/PalEON/SiteSelection'),
setwd('C:/Users/goring/Dropbox/PalEON/SiteSelection'))

That’s right friends, you know what part of my directory tree looks like. It tests whether I am in a ‘unix’ type system, and if I’m not, it gives me a Windows directory. Rad!

While I’m at it, Watch the Throne is a pretty decent album isn’t it?

I modified my code based on code posted by Daniel Sabanes.

Advertisements

Published by

downwithtime

Assistant scientist in the Department of Geography at the University of Wisconsin, Madison. Studying paleoecology and the challenges of large data synthesis.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s