# User agent diagnostic script for RSPM binary packages local({ if (.Platform$OS.type != "unix" || Sys.info()["sysname"] == "Darwin") { message(c( "RStudio Package Manager does not currently support binary packages for MacOS.\n\n", "You can still use the binary repository URLs, but you will only be\n", "provided with source packages for now." )) return(invisible()) } dl_method <- getOption("download.file.method", "") dl_extra_args <- getOption("download.file.extra", "") user_agent <- getOption("HTTPUserAgent", "") if (dl_method == "") { dl_method <- if (isTRUE(capabilities("libcurl"))) "libcurl" else "internal" } default_ua <- sprintf("R (%s)", paste(getRversion(), R.version$platform, R.version$arch, R.version$os)) instruction_template <- 'You must configure your HTTP user agent in R to install binary packages. In your site-wide startup file (Rprofile.site) or user startup file (.Rprofile), add: # Set default user agent %s Then restart your R session and run this diagnostic script again. ' message(c( sprintf("R installation path: %s\n", R.home()), sprintf("R version: %s\n", R.version.string), sprintf("OS version: %s\n", utils::sessionInfo()$running), sprintf("HTTPUserAgent: %s\n", user_agent), sprintf("Download method: %s\n", dl_method), sprintf("Download extra args: %s\n", dl_extra_args), "\n----------------------------\n" )) if (dl_method == "libcurl") { if (!grepl(default_ua, user_agent, fixed = TRUE) || (getRversion() >= "3.6.0" && substr(user_agent, 1, 3) == "R (")) { config <- 'options(HTTPUserAgent = sprintf("R/%s R (%s)", getRversion(), paste(getRversion(), R.version["platform"], R.version["arch"], R.version["os"])))' message(sprintf(instruction_template, config)) return(invisible()) } } else if (dl_method %in% c("curl", "wget")) { if (!grepl(sprintf("--header \"User-Agent: %s\"", default_ua), dl_extra_args, fixed = TRUE)) { ua_arg <- "sprintf(\"--header \\\"User-Agent: R (%s)\\\"\", paste(getRversion(), R.version[\"platform\"], R.version[\"arch\"], R.version[\"os\"]))" if (dl_extra_args == "") { config <- sprintf("options(download.file.extra = %s)", ua_arg) } else { config <- sprintf("options(download.file.extra = paste(%s, %s))", shQuote(dl_extra_args), ua_arg) } message(sprintf(instruction_template, config)) return(invisible()) } } message("Success! Your user agent is correctly configured.") })