R and "Windows" Tips

Running Scripts using "ls" in Sean's Sample Scripts

As we learned in class, this does not work! :( However, its a common problem that is encountered, and there is a simple workaround. Go ahead and redownload the scripts from my Github Repository as a "Zip File" here:


Then go to the "GitHub Networks" folder and open the file "github-v3b-WINDOWS.R"

The difference is one line, where directories are listed:
Windows version of file directory listing
gitLists = shell("dir /B project*edgelist.csv", intern=TRUE)

Mac version of file directory listing
gitLists = system("ls project*edgelist.csv", intern=T)

Note - I replaced the carrot-dash assignment operator because it messes with HTML. "=" serves the same function in R.

Installing Libraries

Found this information HERE

4.2 I don't have permission to write to the R-2.15.3\library directory.
You can install packages anywhere and use the environment variable R_LIBS (see How do I set environment variables?) to point to the library location(s).

Suppose your packages are installed in p:\myRlib. Then you can EITHER

set the environment variable R_LIBS to p:/myRlib before starting R

OR use a package by, e.g.

library(mypkg, lib.loc="p:/myRlib")

You can also have a personal library, which defaults to the directory R\win-library\x.y of your home directory for versions x.y.z of R. This location can be changed by setting the environment variable R_LIBS_USER, and can be found from inside R by running Sys.getenv("R_LIBS_USER"). This will only be used if it exists so you may need to create it: you can use

dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)

to do so. If you use install.packages and do not have permission to write to the main or site library, it should offer to create a personal library for you and install the packages there. This will also happen if update.packages offers to update packages for you in a library where you do not have write permission.

There can be additional security issues under Windows Vista and later: See Does R run under Windows Vista?. In particular, the detection that a standard user has suitable permissions appears to be unreliable under Vista, so we recommend that you do create a personal directory yourself.