Skip to content

Commit

Permalink
Merge pull request #296 from ropensci/sort_pkgs
Browse files Browse the repository at this point in the history
sorting packages
  • Loading branch information
b-rodrigues authored Sep 15, 2024
2 parents a0367da + 8a111a4 commit 881135f
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 127 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test-fetchlocal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ jobs:

- name: Build default.nix with 2 local packages
run: |
nix-shell ./inst/extdata/default.nix --run "Rscript -e \"library(rix);rix('4.3.1', local_r_pkgs = c('chronicler_0.2.1.tar.gz', 'knitr_1.43.tar.gz'), overwrite = TRUE)\""
nix-shell ./inst/extdata/default.nix --run "Rscript -e \"library(rix);rix('4.3.1', local_r_pkgs = c('knitr_1.43.tar.gz', 'chronicler_0.2.1.tar.gz'), overwrite = TRUE)\""
- name: Check generated default.nix
run: cat default.nix

- name: Build default.nix
run: nix-build
Expand Down
18 changes: 13 additions & 5 deletions R/fetchers.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ get_imports <- function(path) {
#' @return A character. The Nix definition to build the R package from local sources.
#' @noRd
fetchlocal <- function(local_pkg) {
its_imports <- get_imports(local_pkg)
its_imports <- get_imports(local_pkg) |>
strsplit(split = " ") |>
unlist()

its_imports <- paste(c("", its_imports), collapse = "\n ")

# Remove package version from name
package_name <- unlist(strsplit(local_pkg, split = "_"))
Expand Down Expand Up @@ -206,24 +210,28 @@ fetchlocals <- function(local_r_pkgs) {
} else if (length(local_r_pkgs) == 1) {
fetchlocal(local_r_pkgs)
} else {
paste(lapply(local_r_pkgs, fetchlocal), collapse = "\n")
paste(lapply(sort(local_r_pkgs), fetchlocal), collapse = "\n")
}
}



#' fetchgits Downloads and installs packages hosted on Git. Wraps `fetchgit()`
#' to handle multiple packages
#' @param git_pkgs A list of four elements: "package_name", the name of the
#' @param git_pkgs A list of three elements: "package_name", the name of the
#' package, "repo_url", the repository's url and "commit", the commit hash of
#' interest. This argument can also be a list of lists of these four elements.
#' interest. This argument can also be a list of lists of these three elements.
#' @return A character. The Nix definition to download and build the R package
#' from Github.
#' @noRd
fetchgits <- function(git_pkgs) {
if (!all(vapply(git_pkgs, is.list, logical(1)))) {
fetchgit(git_pkgs)
} else if (all(vapply(git_pkgs, is.list, logical(1)))) {

# Re-order list of git packages by "package name"
git_pkgs <- git_pkgs[order(sapply(git_pkgs,'[[',"package_name"))]

Check warning on line 233 in R/fetchers.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fetchers.R,line=233,col=48,[commas_linter] Commas should always have a space after.

Check warning on line 233 in R/fetchers.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fetchers.R,line=233,col=48,[quotes_linter] Only use double-quotes.

Check warning on line 233 in R/fetchers.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fetchers.R,line=233,col=53,[commas_linter] Commas should always have a space after.

paste(lapply(git_pkgs, fetchgit), collapse = "\n")
} else {
stop("There is something wrong with the input. Make sure it is either a list of three elements 'package_name', 'repo_url' and 'commit' or a list of lists with these three elements")

Check warning on line 237 in R/fetchers.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fetchers.R,line=237,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 185 characters.
Expand All @@ -242,7 +250,7 @@ fetchzips <- function(archive_pkgs) {
} else if (length(archive_pkgs) == 1) {
fetchzip(archive_pkgs)
} else if (length(archive_pkgs) > 1) {
paste(lapply(archive_pkgs, fetchzip), collapse = "\n")
paste(lapply(sort(archive_pkgs), fetchzip), collapse = "\n")
} else {
stop(
"There is something wrong with the input. Make sure it is either",
Expand Down
7 changes: 5 additions & 2 deletions R/rix_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ get_rpkgs <- function(r_pkgs, ide) {
r_pkgs
}

r_pkgs <- sort(r_pkgs)

rPackages <- paste(c("", r_pkgs), collapse = "\n ")

rPackages <- gsub("\\.", "_", rPackages)
Expand Down Expand Up @@ -161,7 +163,7 @@ generate_local_r_pkgs <- function(local_r_pkgs, flag_local_r_pkgs) {
#' @noRd
generate_tex_pkgs <- function(tex_pkgs) {
if (!is.null(tex_pkgs)) {
tex_pkgs <- unique(c("scheme-small", tex_pkgs))
tex_pkgs <- unique(c("scheme-small", sort(tex_pkgs)))

tex_pkgs <- paste(c("", tex_pkgs), collapse = "\n ")

Expand All @@ -182,7 +184,8 @@ generate_tex_pkgs <- function(tex_pkgs) {
#' @noRd
get_system_pkgs <- function(system_pkgs, r_pkgs) {
# We always need these packages
system_pkgs <- c(system_pkgs, "R", "glibcLocales", "nix")
system_pkgs <- c(system_pkgs, "R", "glibcLocales", "nix") |>
sort()

# If the user wants the R {quarto} package, then the quarto software needs to be installed
system_pkgs <- if (any(grepl("quarto", r_pkgs))) {
Expand Down
47 changes: 24 additions & 23 deletions tests/testthat/_snaps/rix/bleeding_edge_default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,6 @@ let
};

git_archive_pkgs = [
(pkgs.rPackages.buildRPackage {
name = "housing";
src = pkgs.fetchgit {
url = "https://github.com/rap4all/housing/";
rev = "1c860959310b80e67c41f7bbdc3e84cef00df18e";
sha256 = "sha256-s4KGtfKQ7hL0sfDhGb4BpBpspfefBN6hf+XlslqyEn4=";
};
propagatedBuildInputs = builtins.attrValues {
inherit (pkgs.rPackages)
dplyr
ggplot2
janitor
purrr
readxl
rlang
rvest
stringr
tidyr;
};
})


(pkgs.rPackages.buildRPackage {
name = "fusen";
src = pkgs.fetchgit {
Expand All @@ -57,6 +35,28 @@ let
yaml;
};
})


(pkgs.rPackages.buildRPackage {
name = "housing";
src = pkgs.fetchgit {
url = "https://github.com/rap4all/housing/";
rev = "1c860959310b80e67c41f7bbdc3e84cef00df18e";
sha256 = "sha256-s4KGtfKQ7hL0sfDhGb4BpBpspfefBN6hf+XlslqyEn4=";
};
propagatedBuildInputs = builtins.attrValues {
inherit (pkgs.rPackages)
dplyr
ggplot2
janitor
purrr
readxl
rlang
rvest
stringr
tidyr;
};
})

(pkgs.rPackages.buildRPackage {
name = "AER";
Expand All @@ -79,7 +79,8 @@ let
tex = (pkgs.texlive.combine {
inherit (pkgs.texlive)
scheme-small
amsmath;
amsmath
zmsmath;
});

system_packages = builtins.attrValues {
Expand Down
48 changes: 24 additions & 24 deletions tests/testthat/_snaps/rix/code_default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,11 @@ let
inherit (pkgs.rPackages)
data_table
janitor
quarto
languageserver;
languageserver
quarto;
};

git_archive_pkgs = [
(pkgs.rPackages.buildRPackage {
name = "housing";
src = pkgs.fetchgit {
url = "https://github.com/rap4all/housing/";
rev = "1c860959310b80e67c41f7bbdc3e84cef00df18e";
sha256 = "sha256-s4KGtfKQ7hL0sfDhGb4BpBpspfefBN6hf+XlslqyEn4=";
};
propagatedBuildInputs = builtins.attrValues {
inherit (pkgs.rPackages)
dplyr
ggplot2
janitor
purrr
readxl
rlang
rvest
stringr
tidyr;
};
})


(pkgs.rPackages.buildRPackage {
name = "fusen";
src = pkgs.fetchgit {
Expand All @@ -58,6 +36,28 @@ let
yaml;
};
})


(pkgs.rPackages.buildRPackage {
name = "housing";
src = pkgs.fetchgit {
url = "https://github.com/rap4all/housing/";
rev = "1c860959310b80e67c41f7bbdc3e84cef00df18e";
sha256 = "sha256-s4KGtfKQ7hL0sfDhGb4BpBpspfefBN6hf+XlslqyEn4=";
};
propagatedBuildInputs = builtins.attrValues {
inherit (pkgs.rPackages)
dplyr
ggplot2
janitor
purrr
readxl
rlang
rvest
stringr
tidyr;
};
})

(pkgs.rPackages.buildRPackage {
name = "AER";
Expand Down
44 changes: 22 additions & 22 deletions tests/testthat/_snaps/rix/frozen_edge_default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,6 @@ let
};

git_archive_pkgs = [
(pkgs.rPackages.buildRPackage {
name = "housing";
src = pkgs.fetchgit {
url = "https://github.com/rap4all/housing/";
rev = "1c860959310b80e67c41f7bbdc3e84cef00df18e";
sha256 = "sha256-s4KGtfKQ7hL0sfDhGb4BpBpspfefBN6hf+XlslqyEn4=";
};
propagatedBuildInputs = builtins.attrValues {
inherit (pkgs.rPackages)
dplyr
ggplot2
janitor
purrr
readxl
rlang
rvest
stringr
tidyr;
};
})


(pkgs.rPackages.buildRPackage {
name = "fusen";
src = pkgs.fetchgit {
Expand All @@ -57,6 +35,28 @@ let
yaml;
};
})


(pkgs.rPackages.buildRPackage {
name = "housing";
src = pkgs.fetchgit {
url = "https://github.com/rap4all/housing/";
rev = "1c860959310b80e67c41f7bbdc3e84cef00df18e";
sha256 = "sha256-s4KGtfKQ7hL0sfDhGb4BpBpspfefBN6hf+XlslqyEn4=";
};
propagatedBuildInputs = builtins.attrValues {
inherit (pkgs.rPackages)
dplyr
ggplot2
janitor
purrr
readxl
rlang
rvest
stringr
tidyr;
};
})

(pkgs.rPackages.buildRPackage {
name = "AER";
Expand Down
44 changes: 22 additions & 22 deletions tests/testthat/_snaps/rix/other_default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,6 @@ let
};

git_archive_pkgs = [
(pkgs.rPackages.buildRPackage {
name = "housing";
src = pkgs.fetchgit {
url = "https://github.com/rap4all/housing/";
rev = "1c860959310b80e67c41f7bbdc3e84cef00df18e";
sha256 = "sha256-s4KGtfKQ7hL0sfDhGb4BpBpspfefBN6hf+XlslqyEn4=";
};
propagatedBuildInputs = builtins.attrValues {
inherit (pkgs.rPackages)
dplyr
ggplot2
janitor
purrr
readxl
rlang
rvest
stringr
tidyr;
};
})


(pkgs.rPackages.buildRPackage {
name = "fusen";
src = pkgs.fetchgit {
Expand All @@ -57,6 +35,28 @@ let
yaml;
};
})


(pkgs.rPackages.buildRPackage {
name = "housing";
src = pkgs.fetchgit {
url = "https://github.com/rap4all/housing/";
rev = "1c860959310b80e67c41f7bbdc3e84cef00df18e";
sha256 = "sha256-s4KGtfKQ7hL0sfDhGb4BpBpspfefBN6hf+XlslqyEn4=";
};
propagatedBuildInputs = builtins.attrValues {
inherit (pkgs.rPackages)
dplyr
ggplot2
janitor
purrr
readxl
rlang
rvest
stringr
tidyr;
};
})

(pkgs.rPackages.buildRPackage {
name = "AER";
Expand Down
Loading

0 comments on commit 881135f

Please sign in to comment.