unabel to locate ggplot2
Hi,
When I compile as an R-program, Rstudio locates ggplot2. But when I
use knitr, I get the following error message: I have installed all
the packages. I think it is not in the default location. How do I
idnetify whrere it is and how do I redirect RStudio to look
there?
Thanks.
Chetty
library(ggplot2)
Error: package 'reshape' required by 'ggplot2' could not be found
names(cars)
[1] "speed" "dist"
mean(cars$speed)
[1] 15.4
qplot(speed, dist, data = cars)
Error: could not find function "qplot"
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Josh Paulson on 23 Jul, 2012 12:11 AM
Hello,
Sweave and knitr use a separate environment and you'll need to load the library in your script such as
library(ggplot2). See the following documentation:http://rstudio.org/docs/authoring/overview
Josh
Josh Paulson closed this discussion on 23 Jul, 2012 12:11 AM.
chettyvk re-opened this discussion on 23 Jul, 2012 02:10 AM
3 Posted by chettyvk on 23 Jul, 2012 02:15 AM
Thanks Josh. Please note that there is a statement library(ggplot2) and the error message came in spite of that. My memory is that when I installed packages I got a warning that the packages cannot be installed in the default location ant they will be installed in some personal library. SO the package "ggplot2" is there but RStudio is not getting it. How to point to that location?
Thanks.
Chetty
Support Staff 4 Posted by Josh Paulson on 23 Jul, 2012 02:53 PM
Chetty,
Sorry for the confusion and are you saying that when call
library(ggplot2)from the console it works fine, but not inside an Rnw document? We're not doing anything special, but perhaps try putting a call to.libPaths()inside your .Rnw document and looking at the output. This will tell you the path that R is looking for packages. See more at:Josh
5 Posted by chettyvk on 23 Jul, 2012 03:21 PM
Here is the output with .libPaths(). Thanks for any help.
Chetty
library(ggplot2)
Loading required package: reshape
Loading required package: plyr
Attaching package: 'reshape'
The following object(s) are masked from 'package:plyr':
#
rename, round_any
Loading required package: grid
Loading required package: proto
Warning: there is no package called 'proto'
Error: package 'proto' could not be loaded
.libPaths()
[1] "C:/Program Files/R/R-2.15.1/library"
qplot(speed, dist, data = cars)
Error: could not find function "qplot"
Support Staff 6 Posted by Josh Paulson on 23 Jul, 2012 09:46 PM
Chetty,
This seems to be a dependency problem as it says that ggplot2 was able to load, but it's dependencies (proto) failed. Did you recently upgrade versions of R and now the packages are installed into a new directory? The directory you've displayed is a standard location for packages on Windows. If you are still having trouble, you'll need to add the location to your .libpaths for R to pick this up.
Josh
7 Posted by chettyvk on 23 Jul, 2012 10:14 PM
Yes. I upgraded R to the latest version a few days a week ago. How do I add the location to .libpaths?
Is easier to uninstall Rstudion, R etc and reinstall one or more?
Thanks.
Support Staff 8 Posted by Josh Paulson on 24 Jul, 2012 01:03 PM
Chetty,
See the following R documentation:
If you'd rather use environment variables, see the following:
Josh
9 Posted by chettyvk on 25 Jul, 2012 02:04 PM
Thanks. First, I have no problems in my netbook PC with windows7. It works beautifully. My problem is in my desktop with windows XP. I tried the following line listing all my libraries!:
.libPaths("C:\Program Files\R\R-2.15.1\library;C:\Program Files\RStudio\R\library;c:\R\R-2.12.2\library")
Same problem. Will greatly appreciate help!
Thanks again.
Chetty
chettyvk closed this discussion on 27 Jul, 2012 04:18 PM.