5

The R studio I have in my university computer gives me an error when I try to download different packages, whereas when I'm with my laptop in the university server, I don't get this error. Because of this, I don't think that there is some kind of a proxy/server problem.

library(readr)
Error in library(readr) : there is no package called 'readr'

I also tried to download the package using R.exe program or download other packages and it gave me the same error.

After looking for a solution in the internet, I found this script:

install.packages('readr', dependencies = TRUE, repos='http://cran.rstudio.com/')

But it downloaded many different packages: picture

I would like to know the reason why RStudio gives me this error and what happened when I tried to download readr package using install.packages?

zx8754
  • 52,746
  • 12
  • 114
  • 209
M.P.
  • 91
  • 1
  • 1
  • 6

2 Answers2

8

Error in library(readr) : there is no package called 'readr'

This means that you don't have the package readr installed on your computer.

You then installed it with

install.packages('readr', dependencies = TRUE, repos='http://cran.rstudio.com/')

which is good. Most packages are not "stand-alone", they use other packages too, called dependencies. Because you used the default dependencies = TRUE, all the dependencies (and their dependencies) were also installed.

You can look at the CRAN page for readr: https://CRAN.R-project.org/package=readr to see its dependencies (anything in the "Depends" or "Imports" fields is required). And of course you need the dependencies of those dependencies, etc. Now that readr is installed along with its dependencies, you can run library(readr) to load it.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • Thank you! It seems it was a very basic knowledge.. But I'm a little bit confused because I looked my old scrips (and they're not very old because my computer is new) and I have never used install.packages in my laptop, yet the library() script has always worked. Why would that be? – M.P. Nov 20 '17 at 15:56
  • Some packages come pre-installed. You can see the default list [in the official R-FAQ](https://cran.r-project.org/doc/FAQ/R-FAQ.html#Add_002don-packages-from-CRAN). If you are using RStudio, it installs a few more packages too. – Gregor Thomas Nov 20 '17 at 16:12
  • Okay, thanks for explaining! :) Somehow my university computer doesn't have the pre-installed packages which my laptop has. Readr is one example but also dplyr. I wonder why. I have installed myself both R and RStudio in them. – M.P. Nov 20 '17 at 16:19
2

Because you set dependencies = TRUE it installed all the dependencies for the package readr

Those several packages you listed are considered dependencies for readr.

You get that initial error when a package has yet to be downloaded.

Omar Himada
  • 2,540
  • 1
  • 14
  • 31