Join Mark Niemann-Ross for an in-depth discussion in this video Finding libraries for use with R, part of Code Clinic: R.
- Throughout this course, I'll be researching external libraries, installing them to provide R with additional capabilities. I'm finding these libraries at the Comprehensive R Archive Network at cran.r-project.org. You'll see that there are many packages we can use to enhance the functionality of R. In addition to the R libraries, we can look through Google to find things that 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 options for 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 Console in 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 more about the package fun simply by typing a ? and the word fun, and that will pull up the documentation for that particular package. Use R for fun.
I can also list all of the commands currently 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 of all of the various packages, all the various functions in the fun package. Let's go ahead and run Minesweeper because that's what everybody knows. I'll type in Minesweeper, mine_sweeper with a parentheses after it because 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 Minesweeper and pull up the documentation for playing 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 is type 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 have a 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 about how to install packages. The source code for many packages are available at GitHub. In this case, we're looking at the source code for the minesweeper functionality, and in fact, the entire fun package.
Some libraries will not be available for your computer, either because they aren't available for 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 repair these packages, but that's beyond the scope of what we're trying to accomplish with Code Clinic.
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.