When running R, your environment configuration is loaded. These are all the preferences you may set to customize your R session.
To customize these configurations, you must edit your startup file, .Rprofile. This file is available in your home folder. If you're on a mac, you can get your home folder from the command line, use
cd ~ (
~ is the shortcut for your home folder, and
cd is the command for change directory).
Since this file starts with a ".," it means that it is hidden. Configuration files, by default, are hidden. To list hidden files use
ls lists folder contents, and the
-a option shows hidden files. To learn more about the Linux Command Line, check out our tutorial series.
If no configuration files exist, create one.
You may set the default editor used within R with the
Now when you want to edit a file within R, you can pass in the
edit() function, with the name of the file.
Remember that this only works if you're working through the command line, and not if you're on an IDE such as RStudio!
We have already seen how we can run R scripts from outside R, or directly from the command line. To run scripts within your current R session, use the
> source("test.r")  "hello!"
Note that you must have R's current working directory as the folder which contains test.r or R won't be able to find the file. In this case, the error output would look something like this:
> source("test.r") Error in file(filename, "r", encoding = encoding) : cannot open the connection In addition: Warning message: In file(filename, "r", encoding = encoding) : cannot open file 'test.r': No such file or directory
To fix this error message, we may check our working directory with
> getwd()  "/Users/johndoe"
It looks like we set our working directory to our home page. If our test scripts are within the folder test, then we may set it to this with the
> setwd("/Users/johndoe/test") source("test.r")  "hello!"
Great! Now you should be able to run R commands from a file straight from the command line and even within R.
Python Playground is a collection of fun programming projects that will inspire you to new heights. You'll manipulate images, build simulations, and interact with hardware using Arduino & Raspberry Pi. With each project, you'll get familiarized with leveraging external libraries for specialized tasks, breaking problems into smaller, solvable pieces, and translating algorithms into code.$ Check price
This book approaches system administration in a practical way and is an invaluable reference for both new administrators and experienced professionals. It details best practices for every facet of system administration, including storage management, network design and administration, email, web hosting, scripting, and much more.$ Check price