- Throughout this course,I'll be researching external libraries,installing them to provide R with additional capabilities.I'm finding these librariesat the Comprehensive R Archive Networkat cran.r-project.org.You'll see that there are many packages we can useto enhance the functionality of R.In addition to the R libraries,we can look through Google to find thingsthat will help us with specific tasks.For example, I will google R language.

Let's look for a package on image processing.Google will come back with several different optionsfor imaging processing packages that I can use with R.Installing a package is fairly easy.It involves a command called install.packages,which I'll type into the Consolein the lower left-hand corner.install.packages with a parentheses and quote,and then the name of the package.

Let's install a package called fun.I hit return, it downloads the package.Now to make it available to me,I need to type in the command library.There it is, with the name of the package fun.That loads that into local memory.Now I can use the help command to find out moreabout the package fun simply by typing a ?and the word fun, and that will pull upthe documentation for that particular package.Use R for fun.

I can also list all of the commandscurrently in the demo package, using demo package = fun,and I can copy this and then paste it in the console line,and then hit return to run it.You'll see that I now have a list ofall of the various packages, all the various functionsin the fun package.Let's go ahead and run Minesweeperbecause that's what everybody knows.I'll type in Minesweeper,mine_sweeper with a parentheses after itbecause it's a function.

I immediately get an error message.Now I think, "Why did I get an error message?"To find out, I'm going to go back to the package.Actually, I'm going to go back to Minesweeperand pull up the documentation forplaying the minor game in R,so I look down, I read through the documentation,and here towards the bottom,I see it should us Xlib for the x11 device under nix,but I'm on a Macintosh, so what I need to do istype in this beginning command right here.

I'll copy the entire sequence,and then go ahead into the console, paste it in,and hit run.X11 has started, and I now havea copy of Minesweeper running in R.I'll go ahead and click until I-There it is, that's the mine.That's a very simple explanation abouthow to install packages.The source code for many packagesare available at GitHub.In this case, we're looking at the source codefor the minesweeper functionality,and in fact, the entire fun package.

Some libraries will not be available for your computer,either because they aren't availablefor Macintosh or Windows,or they aren't available for your version of R,or they aren't being maintained.For example, install.packages("rimage")returns an error message that says,The package rimage is not available for R version 3.1.2.If you're interested and have the skills,you might have the option to recompile and repairthese packages, but that's beyond the scopeof what we're trying to accomplish with Code Clinic.

Resume Transcript Auto-Scroll

Author

Updated

6/25/2015

Released

4/23/2015

Successful programmers know more than a computer language. They also know how to think about solving problems. They use "computational thinking": breaking a problem down into segments that lend themselves to technical solutions. Code Clinic is a series of ten courses where authors solve the same problems using different programming languages. Here, Mark Niemann-Ross works with R.

Mark introduces challenges and then provides an overview of his solutions in R. Challenges include topics such as statistical analysis, searching directories for images, and accessing peripheral devices.

Visit other courses in the series to see how to solve the exact same challenges in languages like C++, C#, JavaScript, PHP, Python, Ruby, and Swift.

Skill Level Intermediate

3h 24m

Duration

180,592

Views

Show MoreShow Less

Q: R Studio tells me that it can't find files I expect to be available. Where can I find them?

A: Use the setwd() command to set the working directory to match the folder you're working in.

Q: I am unable to access the Lake Pend Oreille data from outside the U.S.

A: A static copy of this data is provided here for lynda.com members outside of the U.S.