Skip to content

Commit b527f08

Browse files
committed
Style via {styler}
1 parent f00e33c commit b527f08

18 files changed

+376
-179
lines changed

R/available_r.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ available_df <- function() {
2222
available_r <- function() {
2323
r_versions <- unique(available_df()$`R.version`)
2424
c(
25-
"bleeding-edge", "frozen-edge", "r-devel", "bioc-devel",
26-
"r-devel-bioc-devel", "latest-upstream", r_versions
25+
"bleeding-edge",
26+
"frozen-edge",
27+
"r-devel",
28+
"bioc-devel",
29+
"r-devel-bioc-devel",
30+
"latest-upstream",
31+
r_versions
2732
)
2833
}
2934

R/ga_cachix.R

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ ga_cachix <- function(cache_name, path_default) {
4848
message("GitHub Actions workflow file saved to: ", path)
4949
}
5050

51-
5251
# The sed command for Darwin is of the form "sed -i '' s/foo/bar"
5352
# while on Linux it's "sed -i s/foo/bar"
5453
darwin_specific_quotes <- if (Sys.info()["sysname"] == "Darwin") {
@@ -59,15 +58,23 @@ ga_cachix <- function(cache_name, path_default) {
5958

6059
system(
6160
paste0(
62-
"sed -i ", darwin_specific_quotes, "'s/CACHE_NAME/", cache_name, "/g' ",
61+
"sed -i ",
62+
darwin_specific_quotes,
63+
"'s/CACHE_NAME/",
64+
cache_name,
65+
"/g' ",
6366
paste0(path, "/cachix_dev_env.yaml")
6467
)
6568
)
6669

6770
system(
6871
paste0(
69-
"sed -i ", darwin_specific_quotes, "'s/PATH_TO_DEFAULT_NIX/",
70-
path_default, "/g' ", file.path(path, "cachix_dev_env.yaml")
72+
"sed -i ",
73+
darwin_specific_quotes,
74+
"'s/PATH_TO_DEFAULT_NIX/",
75+
path_default,
76+
"/g' ",
77+
file.path(path, "cachix_dev_env.yaml")
7178
)
7279
)
7380

R/get_latest.R

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ get_latest <- function(r_version) {
1717
if (nchar(r_version) == 40) {
1818
return(r_version)
1919
} else if (
20-
!(r_version %in% c(
21-
"bioc-devel",
22-
"r-devel-bioc-devel",
23-
"r-devel",
24-
"frozen-edge",
25-
"bleeding-edge",
26-
"latest-upstream"
27-
)) && all(r_version > Filter(function(x) ("latest-upstream" != x), available_r()))
20+
!(r_version %in%
21+
c(
22+
"bioc-devel",
23+
"r-devel-bioc-devel",
24+
"r-devel",
25+
"frozen-edge",
26+
"bleeding-edge",
27+
"latest-upstream"
28+
)) &&
29+
all(
30+
r_version > Filter(function(x) ("latest-upstream" != x), available_r())
31+
)
2832
) {
2933
stop(
3034
"The provided R version is too recent,\nand not yet included in `nixpkgs`.\n",
@@ -36,10 +40,15 @@ get_latest <- function(r_version) {
3640
"'bleeding-edge' and 'frozen-edge'."
3741
)
3842
} else if (
39-
!(r_version %in% c(
40-
"r-devel-bioc-devel", "r-devel", "bioc-devel",
41-
"bleeding-edge", "frozen-edge", available_r()
42-
))
43+
!(r_version %in%
44+
c(
45+
"r-devel-bioc-devel",
46+
"r-devel",
47+
"bioc-devel",
48+
"bleeding-edge",
49+
"frozen-edge",
50+
available_r()
51+
))
4352
) {
4453
stop(
4554
"The provided R version is too recent,\nand not yet included in `nixpkgs`.\n",
@@ -74,7 +83,8 @@ get_right_commit <- function(r_version) {
7483
api_url <- "https://api.github.com/repos/rstats-on-nix/nixpkgs/commits?sha=r-daily"
7584
} else if (
7685
r_version %in% Filter(function(x) `!=`(x, "latest-upstream"), available_r())
77-
) { # all but latest-upstream
86+
) {
87+
# all but latest-upstream
7888
# If a user provides an R version, use most recent date for that version
7989
return(get_date_from_version(r_version))
8090
} else {
@@ -101,17 +111,18 @@ get_right_commit <- function(r_version) {
101111
#' Fetch if available and stop with propagating the curl error. Also show URL
102112
#' for context
103113
#' @noRd
104-
try_get_request <- function(url,
105-
handle,
106-
extra_diagnostics = NULL) {
114+
try_get_request <- function(url, handle, extra_diagnostics = NULL) {
107115
tryCatch(
108116
{
109117
req <- curl::curl_fetch_memory(url, handle)
110118
},
111119
error = function(e) {
112-
stop("Request `curl::curl_fetch_memory(",
113-
paste0("url = ", "'", url, "'", ")` "), "failed:\n ",
114-
e$message[1], extra_diagnostics,
120+
stop(
121+
"Request `curl::curl_fetch_memory(",
122+
paste0("url = ", "'", url, "'", ")` "),
123+
"failed:\n ",
124+
e$message[1],
125+
extra_diagnostics,
115126
call. = FALSE
116127
)
117128
}

R/make_launcher.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@
2222
make_launcher <- function(editor, project_path) {
2323
editor <- trimws(editor)
2424

25-
stopifnot("'editor' argument must be a single word" = grepl("^[A-Za-z]+$", editor))
25+
stopifnot(
26+
"'editor' argument must be a single word" = grepl("^[A-Za-z]+$", editor)
27+
)
2628

2729
if (isFALSE(dir.exists(project_path))) {
2830
dir.create(path = project_path, recursive = TRUE)
2931
project_path <- normalizePath(path = project_path)
3032
}
3133

32-
script_text <- sprintf("#!/usr/bin/env nix-shell\n#!nix-shell default.nix -i bash\n%s", editor)
34+
script_text <- sprintf(
35+
"#!/usr/bin/env nix-shell\n#!nix-shell default.nix -i bash\n%s",
36+
editor
37+
)
3338
script_path <- file.path(project_path, paste0("start-", editor, ".sh"))
3439
writeLines(script_text, script_path)
3540

R/make_nixpkgs_url.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@ make_nixpkgs_url <- function(r_ver = NULL, date = NULL) {
1919

2020
list(
2121
"url" = paste0(
22-
"https://github.com/", github_repo, "archive/", latest_commit, ".tar.gz"
22+
"https://github.com/",
23+
github_repo,
24+
"archive/",
25+
latest_commit,
26+
".tar.gz"
2327
),
2428
"latest_commit" = latest_commit,
2529
"r_ver" = r_ver
2630
)
2731
} else {
2832
list(
2933
"url" = paste0(
30-
"https://github.com/rstats-on-nix/nixpkgs/archive/", date, ".tar.gz"
34+
"https://github.com/rstats-on-nix/nixpkgs/archive/",
35+
date,
36+
".tar.gz"
3137
),
3238
"latest_commit" = date,
3339
"r_ver" = get_version_from_date(date)

R/nix_build_helpers.R

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ fix_ld_library_path <- function() {
6262

6363
#'
6464
#' @noRd
65-
poll_sys_proc_blocking <- function(cmd, proc,
66-
what = c("nix-build", "expr", "nix-hash"),
67-
message_type =
68-
c("simple", "quiet", "verbose")) {
65+
poll_sys_proc_blocking <- function(
66+
cmd,
67+
proc,
68+
what = c("nix-build", "expr", "nix-hash"),
69+
message_type = c("simple", "quiet", "verbose")
70+
) {
6971
what <- match.arg(what, choices = c("nix-build", "expr", "nix-hash"))
70-
message_type <- match.arg(message_type,
72+
message_type <- match.arg(
73+
message_type,
7174
choices = c("simple", "quiet", "verbose")
7275
)
7376
is_quiet <- message_type == "quiet"
@@ -97,13 +100,15 @@ poll_sys_proc_blocking <- function(cmd, proc,
97100
#' with an error code. The waiting is implemented to not create race conditions
98101
#'
99102
#' @noRd
100-
poll_sys_proc_nonblocking <- function(cmd,
101-
proc,
102-
what = c("nix-build", "expr", "nix-hash"),
103-
message_type =
104-
c("simple", "quiet", "verbose")) {
103+
poll_sys_proc_nonblocking <- function(
104+
cmd,
105+
proc,
106+
what = c("nix-build", "expr", "nix-hash"),
107+
message_type = c("simple", "quiet", "verbose")
108+
) {
105109
what <- match.arg(what, choices = c("nix-build", "expr", "nix-hash"))
106-
message_type <- match.arg(message_type,
110+
message_type <- match.arg(
111+
message_type,
107112
choices = c("simple", "quiet", "verbose")
108113
)
109114
is_quiet <- message_type == "quiet"
@@ -119,7 +124,8 @@ poll_sys_proc_nonblocking <- function(cmd,
119124
tools::pskill(pid = proc)
120125
stop(
121126
"`nix_build()` likely interrupted by SIGINT (ctrl+c)\n",
122-
"Stop process with PID ", proc
127+
"Stop process with PID ",
128+
proc
123129
)
124130
}
125131

@@ -151,7 +157,8 @@ nix_build_installed <- function() {
151157
nix_build_exit_msg <- function(x) {
152158
x_char <- as.character(x)
153159

154-
err_msg <- switch(x_char,
160+
err_msg <- switch(
161+
x_char,
155162
"100" = "generic build failure (100).",
156163
"101" = "build timeout (101).",
157164
"102" = "hash mismatch (102).",

R/renv_helpers.R

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ read_renv_lock <- function(renv_lock_path = "renv.lock") {
4040
#' renv_remote_pkgs(read_renv_lock()$Packages)
4141
#' }
4242
renv_remote_pkgs <- function(
43-
renv_lock_remote_pkgs, host = NULL) {
43+
renv_lock_remote_pkgs,
44+
host = NULL
45+
) {
4446
# , "bitbucket", "git", "local", "svn", "url", "version", "cran", "bioc"
4547
supported_pkg_hosts <- c("api.github.com", "gitlab.com")
4648
if (!(is.null(host) || (host %in% supported_pkg_hosts))) {
@@ -61,37 +63,50 @@ renv_remote_pkgs <- function(
6163
host <- renv_lock_pkg_info$RemoteHost
6264
} else {
6365
stop(
64-
renv_lock_pkg_info$Package, " has unsupported remote host: ",
65-
renv_lock_pkg_info$RemoteHost, "\nSupported hosts are: ",
66+
renv_lock_pkg_info$Package,
67+
" has unsupported remote host: ",
68+
renv_lock_pkg_info$RemoteHost,
69+
"\nSupported hosts are: ",
6670
paste0(supported_pkg_hosts, collapse = ", ")
6771
)
6872
}
6973
} else {
7074
if (host != renv_lock_pkg_info$RemoteHost) {
7175
stop(
72-
"Remote host (", renv_lock_pkg_info$RemoteHost, ") of ", renv_lock_pkg_info$Package,
73-
" does not match the provided host (", host, ")"
76+
"Remote host (",
77+
renv_lock_pkg_info$RemoteHost,
78+
") of ",
79+
renv_lock_pkg_info$Package,
80+
" does not match the provided host (",
81+
host,
82+
")"
7483
)
7584
}
7685
}
7786

7887
pkg_info <- vector(mode = "list", length = 3)
7988
names(pkg_info) <- c("package_name", "repo_url", "commit")
80-
switch(host,
89+
switch(
90+
host,
8191
"api.github.com" = {
8292
pkg_info[[1]] <- renv_lock_pkg_info$Package
8393
pkg_info[[2]] <- paste0(
8494
# RemoteHost is listed as api.github.com for some reason
85-
"https://github.com/", renv_lock_pkg_info$RemoteUser, "/",
95+
"https://github.com/",
96+
renv_lock_pkg_info$RemoteUser,
97+
"/",
8698
renv_lock_pkg_info$RemoteRepo
8799
)
88100
pkg_info[[3]] <- renv_lock_pkg_info$RemoteSha
89101
},
90102
"gitlab.com" = {
91103
pkg_info[[1]] <- renv_lock_pkg_info$Package
92104
pkg_info[[2]] <- paste0(
93-
"https://", renv_lock_pkg_info$RemoteHost, "/",
94-
renv_lock_pkg_info$RemoteUser, "/",
105+
"https://",
106+
renv_lock_pkg_info$RemoteHost,
107+
"/",
108+
renv_lock_pkg_info$RemoteUser,
109+
"/",
95110
renv_lock_pkg_info$RemoteRepo
96111
)
97112
pkg_info[[3]] <- renv_lock_pkg_info$RemoteSha
@@ -159,12 +174,13 @@ renv_remote_pkgs <- function(
159174
#' }
160175
#'
161176
renv2nix <- function(
162-
renv_lock_path = "renv.lock",
163-
project_path,
164-
return_rix_call = FALSE,
165-
method = c("fast", "accurate"),
166-
override_r_ver = NULL,
167-
...) {
177+
renv_lock_path = "renv.lock",
178+
project_path,
179+
return_rix_call = FALSE,
180+
method = c("fast", "accurate"),
181+
override_r_ver = NULL,
182+
...
183+
) {
168184
method <- match.arg(method, c("fast", "accurate"))
169185
renv_lock <- read_renv_lock(renv_lock_path = renv_lock_path)
170186
if (method == "fast") {
@@ -175,13 +191,18 @@ renv2nix <- function(
175191
for (i in seq_along(renv_lock$Packages)) {
176192
if (renv_lock$Packages[[i]]$Source %in% c("Repository", "Bioconductor")) {
177193
repo_pkgs[[renv_lock_pkg_names[i]]] <- renv_lock$Packages[[i]]
178-
} else if (renv_lock$Packages[[i]]$RemoteHost %in% c("api.github.com", "gitlab.com")) {
194+
} else if (
195+
renv_lock$Packages[[i]]$RemoteHost %in%
196+
c("api.github.com", "gitlab.com")
197+
) {
179198
remote_pkgs[[renv_lock_pkg_names[i]]] <- renv_lock$Packages[[i]]
180199
} else {
181200
# unsupported_pkgs[[renv_lock_pkg_names[i]]] <- renv_lock$Packages[[i]]
182201
warning(
183-
renv_lock$Packages[[i]]$Package, " has the unsupported remote host ",
184-
renv_lock$Packages[[i]]$RemoteHost, " and will not be included in the Nix expression.",
202+
renv_lock$Packages[[i]]$Package,
203+
" has the unsupported remote host ",
204+
renv_lock$Packages[[i]]$RemoteHost,
205+
" and will not be included in the Nix expression.",
185206
"\n Consider manually specifying the git remote or a local package install."
186207
)
187208
}

0 commit comments

Comments
 (0)