I'm collaborating with a few other users on a variety of R projects. In order to re-use as much code as possible we've created a "stdlib.R" file containing many functions used across multiple projects.
We previously had access to a network drive, so the code could take advantage of the common path by calling:
source("f:/code/stdlib.R")
But now that we're growing up I don't want to depend upon the existence of the network drive (or any hardcoded path for that matter). How can I create code that uses a localized path? Something like this:
source("%localusrpath%/stdlib.R")
where each user has a way to define what %localusrpath% means to them.
For me it could be C:/temp, for another it could be C:/users/user123/documents.
And as long as they set up that "environment variable" then it's going to work for them.
One solution is to use relative paths only:
source("./stdlib.R")
But this will fail if the user ever changes their working directory:
swd("c:/anything_else")
How do I set up a user-specific environment variable through the operating system, and then how can I retrieve/make use of that variable in order to concatenate a path? Or is this whole thing a bad idea?