How to save plots to the file system - r

I followed the steps mentioned here:
http://www.stat.berkeley.edu/~s133/saving.html
xyz <- c(1:4)
yz <- c(10,20,30,40)
jpeg('rplot.jpg')
plot(xyz,yz)
dev.off()
and get the following error:
Warning messages:
1: In jpeg("rplot.jpg") :
unable to load shared object '/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so':
dlopen(/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so, 6): Library not loaded: /usr/X11/lib/libXrender.1.dylib
Referenced from: /Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so
Reason: image not found
2: In jpeg("rplot.jpg") : failed to load cairo DLL
Could anybody suggest what am I doing wrong?

This is clearly on a Mac, code looks correct, throws no error on my Mac, and it suggests that some parts of the grDevices package have gotten corrupted. Unlike vpipkt I think thas is unlikely to have anything to do with how your working directory is set. Since that package is part of the default installation, you will not be able to reinstall it with the GUI package manager. I would recommend reinstalling R.

To get rid of these warnings on my Mac (running OS X El Capitan), I followed this guide. It's for SVGs on OS X Mavericks, but the underlying problem is the same; OS X does not ship with X11 support. You need to download and install XQuartz (there is definitely no need to reinstall R).
After doing this, I ran my code again (in RStudio), but only the first warning disappeared. After logging out, logging back in again, and relaunching RStudio, the second warning also disappeared. I think this process sets XQuartz as your default X11 server.

Related

Problems with PATH variable when installing the GPU version of tensorflow

I am currently working on installing the gpu version of tensorflow onto my computer; however, I am experiencing several difficulties. My initial problem was a relatively common problem where Tensorflow was not able to find the CUDA libraries during installation, and I found a very useful post here on StackOverflow that mentioned that by changing the 'CUDA_PATH' environment variable on my computer and adding the 'bin' folder to said variable's path, Tensorflow should be able to find the CUDA libraries.
This didn't work for me, and so I changed the name of the environment variable 'CUDA_PATH' to simply be 'PATH', since that was the environment variable name that was shown on the post I followed.
It didn't work either so I changed it back. Now, everytime I open RStudio, the following error message appears:
Error in Sys.setenv(PATH = new_path) : wrong length for argument
In addition: Warning message:
In system2(conda, c("run", in_env, run_args, shQuote(cmd), args), :
running command '"C:/Users/maria/AppData/Local/r-miniconda/condabin/conda.bat" run --prefix "C:\Users\maria\AppData\Local\r-miniconda\envs\r-reticulate" --no-capture-output "python" -c "import os; print(os.environ['PATH'])"' had status 1
I have tried uninstalling R, Rtools, Rstudio, miniconda and all my Nvidia GPU drivers, as well as CUDA and CUDANN. I then have re-downloaded every programme, and the error still appears whenever I start a session in Rstudio (before I can even do anything remotely related to tensorflow or before I even use R in any way).
If anyone has any suggestions I would greatly appreciate some help with this issue.
Thanks :)
P.S.: Please find below a screenshot of my RStudio upon opening the programme.

I am unable to use install.packages with the pkgs parameter to install a package from a local file (Win8.1, R3.10)

I am trying to install the rClr package. The instructions for this are to copy the package file onto the local computer and use install.packages(pkgs = "c:/.../rClr_0.5-2.zip"). I have a laptop, a server and a desktop. The laptop and the desktop are Windows 8.1, the server Windows 2012. All run R 3.1.0. The desktop installs rClr without a problem. The other two return the warning (error) message:
package ‘c:/.../rClr_0.5-2.zip’ is not available (for R version 3.1.0).
I've tried all obvious things. The error is pretty generic, it is given whenever install.packages can't find a file. The package is compatible with R 3.1.0, as evidenced by the fact it installs on my desktop. I've check for silly mistakes. I've tried moving the file to simpler directory structures (in case install.packages had a problem with spaces or special characters), I've given it maximum file permissions, tried playing around a few other things, but nothing makes a difference. I also tried replacing the local reference with a reference to the http link, and tried download another random package from CRAN to see if that would install, and both gave the same error message. I can't think of anything different in the environment of the laptop and the desktop. install.packages does work when installing the standard packages from CRAN.
Am I missing something obvious? Is there any known issue with install.packages (I thought maybe security but couldn't find anything on internet)? Are their ways to force an installation? Can anyone recommend something else to try?
Thanks.

Did the subdirectory structure of package repositories change as of R 2.15.2?

Kind of embarrassing / a no-go, but since it hasn't been that long that I've moved from "pure user" to "beginner-developer", I've never actually read the CHANGELOG when a new R version came out - well until today (and I have the feeling I should make this a habbit) ;-)
Yet I'm not sure if the supposed change actually occurred since I couldn't find anything about it at a first glimpse at the CHANGELOG of R R 2.15.2:
Actual question
Is it possible that the (subdirectory) structure of package repositories changed from
./bin/windows/contrib/2.xx/
to
./src/contrib/2.xx/ or even ./src/contrib?
Or at least that the PACKAGES file now needs to live here: ./src/contrib/PACKAGES?
Background info
Up to version 2.15.1, the following path worked to install packages from my local package repository:
path.repos <- "L:/R/packages"
repos <- file.path("file://", path.repos)
Function contrib.url would take repos and expand it to the right subdirectory:
> contrib.url(repos)
[1] "file:///L:/R/packages/bin/windows/contrib/2.15"
But when I try to run install.packages(), I get the following error for R 2.15.2:
> install.packages("mypkg",
+ lib=file.path(R.home(), "library"),
+ repos=repos,
+ type="win.binary"
+ )
Error in read.dcf(file = tmpf) : cannot open the connection
In addition: Warning message:
In read.dcf(file = tmpf) :
cannot open compressed file 'L:/R/packages/src/contrib/PACKAGES', probable reason 'No such file or directory'
>
When I do the same with R 2.15.1, everything works smoothly.
Due dilligence
There are some references with respect to repositories in the CHANGELOG, but the only section I found that gives me some evidence that the supposed change occurred is this:
PACKAGE INSTALLATION
For a Windows or Mac OS X binary package install, install.packages() will check if a source package is available on the same repositories, and report if it is a later version or there is a source package but no binary package available.
Just had a look at the official documentation again and got the idea that maybe arg type is not passed along to contrib.url() correctly as it seems to me install.package() is looking at the place for type="source" packages?
This particular bug isn't the same as mine.
This issue relates to checks install.packages() now runs before installing. As Rappster said, it tries to find a source package to compare the binary version with:
For a Windows or Mac OS X binary package install, install.packages() will check if a source package is available on the same repositories, and report if it is a later version or there is a source package but no binary package available.
So a simple way of squashing this message is creating the R/src/contrib directory and running tools::write_PACKAGES() in that directory to create (an empty) PACKAGES file.
And of course, the reason you aren't getting this message in 2.15.1 is that it doesn't do the checking (see R NEWS quote above) that 2.15.2 performs.
I have submitted a bug report of my issues. No news yet. May post it to the R mailing list as well.

JavaGD fails to load

Could someone please help.
I had Deducer working with R 2.14 but now that I have updated to 2.15.1 I can't get JGR to load. I have loaded JGR and Deducer.
This is the message I get when installing
Loading required package: JavaGD
Error : .onLoad failed in loadNamespace() for 'JavaGD', details:
call: .Call("RegGetStrValue", c(key, "CurrentVersion"), PACKAGE = "JavaGD")
error: C symbol name "RegGetStrValue" not in DLL for package "JavaGD"
Error: package ‘JavaGD’ could not be loaded
I have removed all old versions of R and Ver 2.15.1 - reinstalled R and still get this message.
Is it possible that this is a Registry problem and if so where should I look.
I have searched and although there seem to be simiar reported issues, none are exactly the same from the ones that I have seen. I certainly dont seem to have m,ultiple versions of JavaGD in my library and the Namesake file is in the folder JavaGD.
I am running Win 7 32 bit ver on fairly current Dell Laptop.
R seems to work fine and I am using R-Studio most of the time and that works fine as well.
Any help would be appreciated
7 years on form the OP's original issue choosing the right Java Download is critical for 64-bit machines which most of our RStudio environments are synced to work with. For whatever reason, downloading the 64-bit JRE is difficult. To avoid the same error presented by Deducer more recently be sure to download the 64-bit Java JRE from https://www.java.com/en/download/manual.jsp. Note, the 64-bit version must be downloaded offline as instructed (usually bottom of Windows downloads). Check that the installation path is c:\Program Files\Java and not c:\Program Files(x86)\Java. That plus the JDK should fix this problem going forward.

Error in loading rgl package with Mac OS X

I am trying to install rgl package (0.92.858) for R (2.14.2) under Mac OS X (Lion 10.7.3). When I try to load it (library(rgl)), I get the following error:
Error : .onLoad failed in loadNamespace() for 'rgl', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/2.14/Resources/library/rgl/libs/x86_64/aglrgl.so':
dlopen(/Library/Frameworks/R.framework/Versions/2.14/Resources/library/rgl/libs/x86_64/aglrgl.so, 6): Symbol not found: __ZN3gui13OSXGUIFactory12hasEventLoopEv
Referenced from: /Library/Frameworks/R.framework/Versions/2.14/Resources/library/rgl/libs/x86_64/aglrgl.so
Expected in: dynamic lookup
I have a Mac with Norwegian keyboard. Maybe this has something to do with the issue? However, I get the same error, even though I change the language to U.S. Has anyone experienced similar problem? Any way solving it?
I was having this problem with rgl 0.93.996 on OSX 10.9.2, but then after reinstalling several times I saw "Installing rgl - error: X11 not found but required, configure aborted"
A quick search took me here https://stat.ethz.ch/pipermail/r-sig-mac/2012-March/009077.html
Then I was finally able to get it to work by downloading XQuartz https://www.xquartz.org So it was X11 that was the problem in my case.
It requires building from the source as there is a problem with the path to libpng.dylib path if using the built in source install. The process is:
1) Download the source files from http://download.r-forge.r-project.org/src/contrib/rgl_0.92.879.tar.gz
- You need to download the source files from here since you have to manually install the program.
2) Unzip the files to a convenient location. You can do this by double clicking on the .tar file
3) Open Terminal and navigate to the directory that you placed the files in. I put them on my desktop so the command is:
cd ~/Desktop
4) In Terminal run
R CMD INSTALL --with-libpng-prefix=/usr/X11/lib/ rgl
You can then delete all the files you downloaded. Note that I am running Mac OS X 10.7.3 with R 2.15.0. The specific paths may be slightly different if you are on a different version. You do not need the rgl folder or files after you install them and they can be deleted.
I was still having issues installing from source with special flags or any of the other suggestions in comments and things above. I am using Mac OS X 10.7.3 on a 64-bit MacBook Pro and R 2.15.0
I continued to get the following when loading the rgl package:
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/2.14/Resources/library/rgl/libs/x86_64/aglrgl.so'
I tried the following sub-optimal solution works: Delete the aglrgl.so file. Then try loading the package again.
(This is a suggestion I took from a post by Duncan Murdoch
)
A quick way to delete this file is to type the following into the terminal:
open -a Finder /Library/Frameworks/R.framework/Versions/2.15/Resources/library/rgl/libs/x86_64/
In the new Finder window that pops up, delete the aglrgl.so file, and then close the window. Open the R-GUI, and try loading rgl: library("rgl"). It should work fine, and unfortunately use X11 for the 3D graphics instead of the native Quartz window. For me, this is better than nothing.
The problem is now documented on R-forge :
http://r-forge.r-project.org/tracker/index.php?func=detail&aid=1996&group_id=234&atid=946
You basically have to delete the incriminated file, aglrgl.so. R gives you the file's path in the displayed error message.
The new Mac binary version of rgl 0.92.861 installs on 2.14.2 without error and runs the example code.
Okay solution in my case (OS X Yosemite), first download the RGL source (not binaries) in http://cran.r-project.org/src/contrib/rgl_0.95.1247.tar.gz, extract it, and build the library using this command:
R CMD INSTALL --disable-cocoa --x-includes=/usr/X11/ rgl
and it works like a charm.

Resources