Skip to content

Commit

Permalink
simplify repos handling (#1971)
Browse files Browse the repository at this point in the history
* simplify repos handling

* fixups
  • Loading branch information
kevinushey authored Aug 20, 2024
1 parent 7c6cd46 commit 6b123fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 36 deletions.
2 changes: 0 additions & 2 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,8 @@ renv_init_repos <- function(repos = getOption("repos")) {

if (isdefault) {
repos[["CRAN"]] <- config$ppm.url()
return(repos)
}

# repos appears to have been configured separately; just use it
repos

}
Expand Down
43 changes: 9 additions & 34 deletions R/lockfile.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,26 @@ renv_lockfile_init_r_version <- function(project) {

}

renv_lockfile_init_r_repos <- function(project) {
renv_lockfile_init_r_repos <- function(project, repos = getOption("repos")) {

repos <- getOption("repos")

# save names
nms <- names(repos)

# force as character
repos <- as.character(repos)

# clear RStudio attribute
# unset the RStudio attribute if it was set
attr(repos, "RStudio") <- NULL

# check for default repositories
#
# note that if the user is using RStudio, we only want to override
# the repositories if they haven't explicitly set their own repo URL
#
# https://github.com/rstudio/renv/issues/1782
rstudio <- structure(
list(CRAN = "https://cran.rstudio.com/"),
RStudio = TRUE
)

isdefault <-
identical(repos, list(CRAN = "@CRAN@")) ||
identical(repos, rstudio)
# make sure it's a character vector in this scope
repos <- convert(repos, "character")

if (isdefault) {
repos[["CRAN"]] <- config$ppm.url()
}
# make sure a CRAN repository is set
cran <- getOption("renv.repos.cran", "https://cloud.r-project.org")
repos[repos == "@CRAN@"] <- cran

# remove PPM bits from URL
if (renv_ppm_enabled()) {
pattern <- "/__[^_]+__/[^/]+/"
repos <- sub(pattern, "/", repos)
}

# force as list
repos <- as.list(repos)

# ensure names
names(repos) <- nms

repos
# all done; return as list
convert(repos, "list")

}

Expand Down

0 comments on commit 6b123fb

Please sign in to comment.