Installing WVPlots and “knitting R markdown”
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Some readers have been having a bit of trouble using devtools
to install WVPlots
. I thought I would write a note with a few instructions to help. These are things you should not have to do often, and things those of us already running R
have stumbled through and forgotten about.
First you will need install (likely admin) privileges on your machine and a network connection that is not blocking and of cran, RStudio or Github.
Make sure you have up to date copies of both R and RStudio. We have to assume you are somewhat familiar with R and RStudio (so suggest a tutorial if you are not).
Once you have these we will try to “knit” or render a R markdown document. To do this start RStudio select File->"New File"->"R Markdown"
as shown below (menus may be different on different systems, you will have to look around a bit).
Then click “OK”. Then press the “Knit HTML” button as shown in the next figure.
This will ask you to pick a filename to save as (anything ending in “.Rmd” will do). If RStudio asks to install anything let it. In the end you should get a rendered copy of RStudio’s example document. If any of this doesn’t work you can look to RStudio documentation.
Assuming the above worked paste the following commands into RStudio’s “Console” window (entering a “return” after the paste to ensure execution).
[Note any time we say paste or type, watch out for any errors caused by conversion of normal machine quotes to insidious smart quotes.]
install.packages(c('RCurl','ggplot2','tidyr',
'devtools','knitr'))
The set of packages you actually need can usually be found by looking at the R
you wish to run and looking for any library()
or ::
commands. R scripts and worksheets tend not to install packages on their own as that would be a bit invasive.
If the above commands execute without error (messages and warnings are okay) you can then try the command below to install WVPlots
:
devtools::install_github('WinVector/WVPlots',
build_vignettes=TRUE)
If the above fails (some Windows users are seeing “curl” errors) it can be a problem with your machine (perhaps permissions, or no curl library installed), network, anti-virus, or firewall software. If it does fail you can try to install WVPlots
yourself by doing the following:
- Navigate a web browser to http://winvector.github.io/WVPlots/.
- From there download the file
WVPlots_0.1.tar.gz
. - In the RStudio “Consoel” window type:
install.packages('~/Downloads/WVPlots_0.1.tar.gz',repos=NULL)
(replacing'~/Downloads/WVPlots_0.1.tar.gz'
with wherever you downloadedWVPlots_0.1.tar.gz
to).
If the above worked you can test the WVPlots
package by typing library("WVPlots")
.
Now you can try knitting one of our example worksheets.
- Navigate a web browser to https://github.com/WinVector/Examples/blob/master/PCR/XonlyPCA.Rmd
- Download the file
XonlyPCA.Rmd
by right-clicking on the “Raw” button (towards the top right). - Rename the downloaded file from
XonlyPCA.Rmd.txt
toXonlyPCA.Rmd
. - In Rstudio use
File->"Open File"
to openXonlyPCA.Rmd
. - Press the “Knit HTML” button (top midle of the editor pane) and this should produced the rendered result.
If this isn’t working then something is either not installed or configured correctly, or something is blocking access (such as anti-virus software or firewall software). The best thing to do is find another local R
user and debug together.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.