2

I am currently working on an assignment (using Windows 7 Professional machine) whereby I have to be using 'datasets' package within knitr document. Since I am trying to knit my document, I have to provide website to CRAN mirror as repo when using install.packages() command. Following is my chunk of my code:

list.of.packages <- c ('R.utils', 'googleVis', 'choroplethr', 'datasets', 'MASS')
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) {
    install.packages(new.packages, repos="http://cran.rstudio.com/")
    lapply (new.packages, require, character.only = TRUE)
} else {
    lapply(list.of.packages, require, character.only = TRUE)
}

However, I get the following error:

Quitting from lines 13-16 (Preview-191015a600a.Rmd) 
Error in contrib.url(repos, "source") : 
  trying to use CRAN without setting a mirror
Calls: <Anonymous> ... withVisible -> eval -> eval -> install.packages -> contrib.url
Execution halted

If I remove 'datasets' from package list, the program runs without any issues. So, I tried looking for 'datasets' package on http://cran.rstudio.com/ website and did not find datasets package. I understand that this is the reason why my knitr is throwing an error.

However, I am surprised not to see 'datasets' package on the cran website. I am new to R, so am not sure if this has always been the case. I have tried looking for datasets package mirror all over the web, but to no avail.

Does anyone have link to datasets package repo on CRAN?

Appreciate your help!

user3694373
  • 140
  • 1
  • 9
  • 2
    datasets is a package installed with R by default. – Dason Aug 22 '14 at 20:14
  • `datasets` is a base package: https://stackoverflow.com/questions/9700799/what-is-difference-between-r-base-and-r-recommended-packages – rcs Aug 22 '14 at 20:24
  • That is what I thought too. I checked my RStudio packages and it was missing. I tried installing it..initially it gave me an error: install.packages('datasets') Warning in install.packages : package ‘datasets’ is not available (for R version 3.1.1) Later, I copied over 'datasets' folder from my R-3.0.3 library to R-3.1.1 library and it started working. However, it is still not working within knitr. – user3694373 Aug 22 '14 at 20:26
  • How did you check for the package? Does `library(datasets)` throw an error? – tkmckenzie Aug 22 '14 at 20:28
  • Yes, library(datasets) threw an error as follows: library(datasets) Error in library(datasets) : ‘datasets’ is not a valid installed package – user3694373 Aug 22 '14 at 20:33
  • 1
    That is really strange, it should be present in your R installation. The easiest thing to do might be re-installing R, I'm not sure how you'd go about installing a package that comes with the R installation (similar case for `base`, `stats`, etc.). – tkmckenzie Aug 22 '14 at 20:46
  • I know..am bumped too. I got it fixed within my R environment. However, am still having issues when I try to knit a document. Any ideas? – user3694373 Aug 22 '14 at 21:04
  • I suspect your R installation is screwed up somehow. Consider re-installing. – Joe Aug 22 '14 at 22:12
  • Thanks guys for all your comments. I will try re-installing R again and let you know. Appreciate your time! – user3694373 Aug 23 '14 at 00:23
  • On my windows machine, I uninstalled and re-installed R and R studio again and that worked. I also copied my code over to my Mac machine and it was running just fine. So, it was an issue with R installation. Thank you all for all your answers and time! – user3694373 Aug 23 '14 at 19:37

0 Answers0