0

A bit of background

I have just downloaded R as I need to run a couple of regressions for my Econometrics project. I have zero experience in R and suspect that my question is rather stupid but I wasn't able to find any information

So I am trying to install a package, namely 'midasr'. However, R does not let me do so as it keeps saying that a 'prerequisite' package is missing. I was adding them manually but it just seems that there is no end as it keeps asking me to download yet another package.

My question is:

Can I, in any way, obtain a complete list of all the packages that I need in order to open the one I want to? If so, could you please tell me how to do it?

Thanks

CONSOLE OUTPUT

> install.packages("midasr",dep=TRUE)
trying URL 'https://cran.cmm.msu.ru/bin/macosx/el-capitan/contrib/3.6/midasr_0.7.tgz'
Content type 'unknown' length 1099289 bytes (1.0 MB)
==================================================
downloaded 1.0 MB

When I try to install 'midasr', it still gives me the error:

The downloaded binary packages are in
    /var/folders/j2/0fn1rd394wz2kzsw3_wqp7540000gn/T//RtmpNqlYdC/downloaded_packages
Error: package or namespace load failed for ‘midasr’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 there is no package called ‘urca’

After I manually add 'urca', it just gives me another package that is needed to be installed.

Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
Tamerbei
  • 3
  • 2
  • See andilabs' comment [here](https://stackoverflow.com/a/14172931/10323798) for a TLDR. `install.packages("my_package",dep=TRUE)`. [This](https://stackoverflow.com/questions/25721884/how-should-i-deal-with-package-xxx-is-not-available-for-r-version-x-y-z-waa) will likely help you somewhere. – NelsonGon Apr 08 '20 at 13:49
  • I suspect that one of the dependencies is failing to install. If you carefully look at the console output, you will be able to identify which package is failing and perhaps a reason. If you're still having trouble, consider providing the console output as an edit to your original question. – Ian Campbell Apr 08 '20 at 13:55
  • 1
    @NelsonGon It works now, I just had to try to install it once again. I still have no clue how that works but the issue is solved. Thank you! – Tamerbei Apr 08 '20 at 14:22

2 Answers2

0

I think your repo is out of date. Try this.

options(repos='http //cran.rstudio.com/')
install.packages("midasr",dep=TRUE) 
Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
0
project_pkgs <- c(
  "midasr"
)

# pacman is a faster installation 
pacman::p_load(project_pkgs,character.only = T)

I put together a function ( based on SO helps) for automated installation of libraries. Its handy if your packages are from CRAN or Github or also from Bioconductor). And, also checks for your OS

# Automate package installation -------------------------------------------
if (.Platform$OS.type == "windows") {
  if ("BiocManager" %in% rownames(installed.packages()) == FALSE) {
    install.packages("BiocManager")
  }
  ProjectLibraries <- function(pkgs) {
    library(BiocManager)

    check <-
      sapply(pkgs,
        require,
        warn.conflicts = TRUE,
        character.only = TRUE
      )
    if (any(!check)) {
      message("Loading missing packages for the project")
      pkgs.missing <- pkgs[!check]
      BiocManager::install(pkgs.missing, ask = F)
      check <-
        sapply(pkgs.missing,
          require,
          warn.conflicts = TRUE,
          character.only = TRUE
        )
    } else {
      print(check)
      message("All project packages are loaded")
    }
  }
} else {
  ProjectLibraries <- function(pkgs) {
    sapply(pkgs,
      require,
      warn.conflicts = TRUE,
      character.only = TRUE
    )
  }
}

# usage
ProjectLibraries(project_pkgs)
user5249203
  • 4,436
  • 1
  • 19
  • 45