-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Option to install R packages from DESCRIPTION file
- Loading branch information
Showing
6 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
set -ex | ||
|
||
R --version | ||
radian --version | ||
|
||
for package in readr stringr data.table yaml testthat; do | ||
Rscript -e "library($package)" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Type: Package | ||
Package: myPackage | ||
Title: Devenv test R Package | ||
Version: 0.0.0.1 | ||
Imports: | ||
readr, | ||
stringr, | ||
nonexistentpackage | ||
Depends: | ||
data.table, | ||
yaml | ||
Suggests: | ||
testthat (>= 3.0.0) | ||
Encoding: UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
let | ||
strings = import ./utils/strings.nix; | ||
inherit (builtins) | ||
concatMap | ||
filter | ||
hasAttr | ||
replaceStrings | ||
warn | ||
; | ||
inherit (strings) | ||
matches | ||
extractWithRegex | ||
splitWithRegex | ||
; | ||
in | ||
rec { | ||
getSection = | ||
section: descriptionFile: | ||
extractWithRegex ".*${section}:\n +([a-zA-Z0-9., (>=)\n]*)\n[A-Z].*" descriptionFile; | ||
extractPackages = packages: filter (matches "^[a-zA-Z0-9.]+") packages; | ||
extractSectionPackages = section: extractPackages (splitWithRegex "[\n, ]+" section); | ||
descriptionPackages = | ||
descriptionFile: | ||
concatMap (section: extractSectionPackages (getSection section descriptionFile)) [ | ||
"Imports" | ||
"Depends" | ||
"Suggests" | ||
]; | ||
normalizePackageName = pkg: replaceStrings [ "." ] [ "_" ] pkg; | ||
getRPackage = | ||
pkg: pkgs: | ||
let | ||
pkgName = normalizePackageName pkg; | ||
in | ||
if hasAttr pkgName pkgs.rPackages then | ||
pkgs.rPackages.${pkgName} | ||
else | ||
warn "Package \"${pkgName}\" does not exist in nixpkgs." null; | ||
getRPackages = | ||
pkgs: descriptionFile: | ||
filter (pkg: pkg != null) (map (pkg: getRPackage pkg pkgs) (descriptionPackages descriptionFile)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
let | ||
inherit (builtins) | ||
filter | ||
head | ||
isNull | ||
isString | ||
match | ||
split | ||
; | ||
in | ||
{ | ||
# matches :: string -> string -> bool | ||
matches = pattern: text: !isNull (match "(${pattern})" text); | ||
# extractWithRegex :: string -> string -> string | ||
extractWithRegex = | ||
regex: string: | ||
let | ||
matched = match regex string; | ||
in | ||
if isNull matched then "" else head matched; | ||
# splitWithRegex :: string -> string -> [string] | ||
splitWithRegex = regex: string: filter isString (split regex string); | ||
} |