The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

File system navigation in R

Martin R. Smith martin.smith@durham.ac.uk

2024-07-25

Before you can open a file, you need to tell R where to find it. You can do this by providing the full path to the file on your system. Be careful to use forward slashes (/, not \, which you’ll get if you copy file paths in Windows).

filename <- "C:/nexus/matrix.nex"

You can save typing by giving R a working directory. You can think of R as having a file explorer window open invisibly in the background.

You can see the folder that’s open at the moment by typing getwd() at the console.

setwd() tells R to open a different folder instead.

setwd('../') tells R to go up to a parent directory. (You can do this using the Graphical User Interface in RStudio).

By setting the directory that your files are in as the working directory, you only need to specify the filename:

setwd("C:/nexus/") # You only need to do this once
filename <- "matrix.nex"
# Do something with this file
#

filename <- "tree.nex"
# Do something with this file
#

What next?

Now you know how to locate files, you might want to load a dataset or phylogenetic tree into R.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.