R: Getting Past the Blinking Cursor

Hello everyone!

I want to start by talking about my struggles when beginning to work in R. My first exposure to R (and programming in general) was in a Phylogenetic Methods course. I should note that I consider myself barely computer literate. Never in a million years did I think that as a biologist, I would have to work through a command line/code/script/programing language/whatever the correct lingo is. When we first fired up R in class, I looked at that blank console with the blinking cursor and I thought “Now what??” There are an infinite number of things I could type into the blank space. Unfortunately, most of those entries will yield error messages. So how do I use R to produce something meaningful? I found that there were 2 key things that began to open the door for me. These may seem silly, but they are really not trivial.

  1. Know what a working directory is and how to use it.
    1. Believe it or not, I didn’t fully understand a working directory until about halfway through the semester. A working directory is essentially a file folder that you tell R you are going to work out of. When you try to load data, R will be looking for the file in your working directory. In addition, when you save code, plots, etc., they will be saved to your working directory. It can be helpful to create a file folder specifically for your work in R so that you do not constantly need to change your working directory or specify paths to different files.
    2. But how do you know what folder is your working directory? It’s simple, just use the function getwd() and R will return the path to your current working directory. This function is useful because if you don’t specify a working directory, R will set one for you as a default.
    3. How do you set your working directory? The function setwd() allows you to specify your working directory. In the parentheses, enter the path to your desired file folder.
  2. Learn how to read help files.
    1. This seems simple enough, but the help files also appear to be written in R. It takes practice, but once you start to become familiar with R syntax, the help files will begin to make more sense. It took me an entire semester of working in R before I could read and understand help files. Now, I use them all the time!

A few other useful R basics to learn:

  • How to install and use packages (yay, we went over it in class!)
  • GOOGLE: If you are trying to do something in R and the help files are not doing it for you, google! There are a ton of resources out there and lots of people trying to troubleshoot their code. Even copying and pasting an error message into google can be very helpful. Most likely, you are not the first person to get that error and you may find a page where the error message is explained.

Now I would like to open it up to discussion. What specific challenges have you faced in learning a programming language? Do you have any tricks that make it easier? What do you think are the most important things for a beginner in R to know?

Happy coding!

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to R: Getting Past the Blinking Cursor

  1. jebyrnes says:

    I’d also point out rseek.org – it’s basically google for R related information (I think it’s a filter on top of google). Very useful. There are also often useful tidbits on Stackoverflow and the excellent Crossvalidated which are Q&A sites for programming and stats, respectively. You’ll notice a lot of recent questions on SO about R Markdown for presentations, actually…

  2. martinew says:

    I like the tutorials that I’ve found on the internet. I type in something that I want to do, for example run a two-way ANOVA or calculate phylogenetic beta-diversity for species at my sites, and more often that not I find a nice document that walks me through an analysis. It’s a double-edged sword though. While the tutorials are extremely helpful they remove a lot of the thought process. You don’t, for instance, have to think about what the functions you are typing actually do, or figure out how to write a loop that will display phylogenies for all of your sites. Overall though I find the wealth of support on the internet for R very time and sanity saving and I am extremely grateful to all those that have done most of the hard work for me.

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