How to install 'XLConnect'-package in R correctly - r

I am very new to this community.
My aim is to use R for statistical analysis but some errors occurred.
In the first step, I want to load the "XLConnect"-package, in order to open an xlsx-data file, with this code:
install.packages('XLConnect')
library(XLConnect)
Answer was "package ‘XLConnect’ successfully unpacked and MD5 sums checked", after which the following error was given:
Error in library(XLConnect) : the package ‘XLConnect’ doesn't exist.
I also tried the xlsx package, but in this case always got:
Error in -library('openxlsx') : invalid argument to unary operator
or, that the package openxlsx, doesn't exist but some line before it told me the download, installation and check sums were correct!
Additionally, when I try to change the directory in a script, using
getwd(), the following error occurs:
Error in -getwd() : invalid argument to unary operator
When I type it in the console it works.
I downloaded R here: https://cran.r-project.org/bin/windows/base, installed R version 3.4.3 as well as R Studio.
I already looked in the community for some hints but neither could solve my problem:
XLConnect function is not passing argument to system.file
Error when installing XLConnect in RStudio
MY OS is Windows 10, I tried the 32-bit as well as the 64-bit version of R and installed fitting Java-Versions for both verisons( that was the first error that occured but now isn't there anymore).
I tried to load the packages from several CRAN-Mirrors but always the same error occurs (e.g. Germany(Göttingen),Germany(Münster), Belgium(Ghent) or Switzerland ).
Maybe I missed some very basic setting. Is the information I provided enough or do you need more?
Thanks a lot in advance for your support!

Thanks a lot! I installed java 32-bit and 64-bit versions the way it is recommended here: https://www.r-statistics.com/2012/08/how-to-load-the-rjava-package-after-the-error-java_home-cannot-be-determined-from-the-registry/ and I installed the rJava package like this: install.packages("rJava")
library(rJava) and here: https://askubuntu.com/questions/176115/what-is-the-best-way-of-installing-the-r-package-xlconnect I found that this here should work to register R correctly: sudo R CMD javareconf but then I get the error that the console got an unexpected symbol. Or Do you know how to register Java Development Kit in R correctly. I installed jdk-8u161-windows-x64.

Make sure you have Java Development Kit installed and correctly registered in R.

Related

Trying to install library 'quantmod' in R

I'm trying to download library 'quantmod' in R:
install.packages("quantmod")
console:
The downloaded source packages are in
‘/tmp/RtmpwSKGIl/downloaded_packages’
then:
library("quantmod", lib.loc="/tmp/RtmpwSKGIl/downloaded_packages")
console:
Error in library("quantmod", lib.loc = "/tmp/RtmpwSKGIl/downloaded_packages") :
there is no package called ‘quantmod’
What is the problem?
I get no problem when I try to load this package.Have you tried to provide R the full name path to your package file directory ?C:/Users/...Is your R version up to date ? Try to check if you have the latest, I tried and it worked with :
R 3.3.3
If you are a Windows or MAC user you might want to force the download of the package from source to binary, this can be done by setting the right options in the install.packages command:
options(install.packages.check.source = "no")
https://stat.ethz.ch/R-manual/R-devel/library/utils/html/install.packages.html
I guess I am a year late, but just got out of this situation by installing the Package from R (instead of RStudio) by changing the CRAN.
You can then run library(quantmod) in Rstudio. Hope this works(worked?) for you too.
I am ready to go now!

errors when installing older dplyr package in R

Im a bit new to R and need to use/adapt someone else code in R.
My supervisor uses R version 3.2.2 with the dplyr package version 0.4.3 (to overcome errors and problems with the original code).
I tried to install the older dplyr package with different methods:
- installed devtools package and then used the url devtools::install_url("http://cran.r-project.org/src/contrib/Archive/dplyr/dplyr_0.1.2.tar.gz")
- manual installation (where I downloaded the file and tried to install it.) Installation seemed to have worked but when I run the code it gives a fatal error massage
Every way I've tried so far either gives a lot of error messages or a fatal error and shutdown.
When using help ?dplyr it gives a pop-up that there is an error. Does anybody have any other ideas to install this package?
Thanks!

Changes in install.packages() from R 3.1.2 to R 3.2.1

I am working on a Windows 7 machine without internet access. As yet, I got around the missing internet connection by creating a local copy of the binary CRAN repository in //server/x/bin/windows/contrib/3.1, then running write_PACKAGES("//server/x/bin/windows/contrib/3.1") and finally setting r["CRAN"]="file:////server/x";r["CRANextra"]=r["CRAN"]; in C:/Program Files/R/R-3.1.2/etc/Rprofile.site.
But this does not work any longer since R 3.2.1. The path in the error message of install.packages indicates that R is looking for the source package:
Cannot open compressed file '//server/x/src/contrib/PACKAGES'
I have thought that R on Windows only looks for binary packages!
Looking at a diff between install.packages for 3.1.2 and 3.2.1, I can see quite a few changes. However, the source code for the function has 500+ lines which makes it hard for me to see where specifically the problem lies.
I have tried to set
options(install.packages.check.source="no")
and to explicitly add type="win.binary" to install.packages - both without success.
It is also interesting that
contrib.url(options("repos")$repos["CRAN"],type="win.binary")
gives the correct path file:////server/x/bin/windows/contrib/3.2 but somehow this is not used by install.packages(...,type="win.binary")...
So my question is whether you guys have experienced similar problems?
If no, I would be grateful for any pointers to mistakes I could have made.
I have found the problem.
The R 3.2.1 NEWS section (https://cran.r-project.org/src/base/NEWS) says
The default for option pkgType on platforms using binary packages is now "both", so source packages will be tried if binary versions
are not available or not up to date.
The problem is that RStudio does not directly call install.packages but via a few other functions such as .rs.callAs. In one of these functions, available.packages() gets called without any arguments. So it determines the argument type via getOption("pkgType"). But since R 3.2.1 this is now "both" and not "win.binary" as in R 3.1.2.
A quick workaround for the problem is thus to add
options(pkgType="win.binary")
to the yourRinstallpath/etc/Rprofile.site

errors installing 'sads' package

I am trying to install the sads package (on a Mac OSX) from the beta version which I have downloaded from:
http://ecologia.ib.usp.br/let/doku.php?id=engl:tutorials:rcode#species_abundance_distributions
I then run:
install.packages('~/Desktop/sads_0.1.03.tar.gz', repos=NULL)
and get the error message:
Error: file ‘~/Desktop/sads_0.1.03.tar.gz’ is not an OS X binary package
Any idea how to resolve this and install the package? It looks really useful.
Thanks.
The file you downloaded is not a Mac OS binary package, which is the default for install.packages. Like #sgibb said, you need to specify type = 'source' to force R to look for a source package that you are then going to build yourself. In case the package only contains R code this is quite straightforward. If code needs to be compiled, this could be a more involved process.

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.

Resources