How does RStudio install Rtools?

I just posted an issue on stan-dev/rstan. It relates to the devtools-rstudio interface, specifically to the way in which RStudio installs Rtools once activated by a call to pkgbuild::has_build_tools(). The automated install is doing something I am not able to replicate with a manual install, and the manual install is causing rstan to fail. A good starting point would be to know precisely what this install script does. I'm hoping someone in the RStudio community can point me in the right direction. Perhaps the script is open code and I can just inspect it?

You can check the code of any function by typing the function name without parenthesis, try typing this in the console.

pkgbuild::has_rtools

Also https://github.com/r-lib/pkgbuild/blob/94d2f0da8a49fe9bec5a7f5e9608b7dead959b7c/R/rtools.R

Thanks for the tip.

pkgbuild::has_rtools gives me

  > pkgbuild::has_rtools
  function (debug = FALSE) 
  {
    if (!debug && rtools_path_is_set()) 
        return(!identical(rtools_path(), ""))
    if (!is_windows()) 
        return(FALSE)
    from_config <- scan_config_for_rtools(debug)
    if (is_compatible(from_config)) {
        if (debug) 
            cat("Found compatible gcc from R CMD config CC\n")
        rtools_path_set(from_config)
        return(TRUE)
    }
    from_path <- scan_path_for_rtools(debug)
    if (is_compatible(from_path)) {
        if (debug) 
            cat("Found compatible gcc on path\n")
        rtools_path_set(from_path)
        return(TRUE)
    }
    if (!is.null(from_path)) {
        if (is.null(from_path$version)) {
            if (debug) 
                cat("gcc and ls on path, assuming set up is correct\n")
            return(TRUE)
        }
        else {
            message("WARNING: Rtools ", from_path$version, " found on the path", 
                " at ", from_path$path, " is not compatible with R ", 
                getRversion(), ".\n\n", "Please download and install ", 
                rtools_needed(), " from ", rtools_url, ", remove the incompatible version from your PATH.")
            return(invisible(FALSE))
        }
    }
    registry_candidates <- scan_registry_for_rtools(debug)
    if (length(registry_candidates) == 0) {
        message("WARNING: Rtools is required to build R packages, but is not ", 
            "currently installed.\n\n", "Please download and install ", 
            rtools_needed(), " from ", rtools_url, ".")
        return(invisible(FALSE))
    }
    from_registry <- Find(is_compatible, registry_candidates, 
        right = TRUE)
    if (is.null(from_registry)) {
        versions <- vapply(registry_candidates, function(x) x$version, 
            character(1))
        message("WARNING: Rtools is required to build R packages, but no version ", 
            "of Rtools compatible with R ", getRversion(), " was found. ", 
            "(Only the following incompatible version(s) of Rtools were found:", 
            paste(versions, collapse = ","), ")\n\n", "Please download and install ", 
            rtools_needed(), " from ", rtools_url, ".")
        return(invisible(FALSE))
    }
    installed_ver <- installed_version(from_registry$path, debug = debug)
    if (is.null(installed_ver)) {
        message("WARNING: Rtools is required to build R packages, but the ", 
            "version of Rtools previously installed in ", from_registry$path, 
            " has been deleted.\n\n", "Please download and install ", 
            rtools_needed(), " from ", rtools_url, ".")
        return(invisible(FALSE))
    }
    if (installed_ver != from_registry$version) {
        message("WARNING: Rtools is required to build R packages, but no version ", 
            "of Rtools compatible with R ", getRversion(), " was found. ", 
            "Rtools ", from_registry$version, " was previously installed in ", 
            from_registry$path, " but now that directory contains Rtools ", 
            installed_ver, ".\n\n", "Please download and install ", 
            rtools_needed(), " from ", rtools_url, ".")
        return(invisible(FALSE))
    }
    rtools_path_set(from_registry)
    TRUE
  }

I can't seem to locate where the dialog is launched. The text in the dialog / modal says "Building R package from source requires installation of additional build tools." and a google search on this string doesn't seem to lead me anywhere helpful.

I've looked inside scan_config_for_rtools and scan_registry_for_rtools too, they don't seem to do what I'm looking for.

Any thoughts?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.