* Wrapping an R script: how do I compose the R_LIBS_SITE environment variable?
@ 2021-02-05 16:14 divoplade
2021-02-06 13:53 ` zimoun
0 siblings, 1 reply; 7+ messages in thread
From: divoplade @ 2021-02-05 16:14 UTC (permalink / raw)
To: help-guix
Dear guix,
I am using guix to write R packages. For convenience, I created a small
R script that does the job.
To make this script work as-is, I wrapped it using wrap-program. wrap-
program creates a shell script that sets up environment variables and
then call the real script, because R needs to be able to find all the
packages and dependencies. More specifically, I need to extend the
R_LIBS_SITE environment variable to point to all the R dependencies of
my package, as well as their recursive dependencies.
How do I compute that? I only care about R dependencies, so using the
whole recursive dependency tree of my package seems too much.
My current solution is to save the R_LIBS_SITE environment from the
build procedure and just use that. The obvious problem is that it also
contains build dependencies, and I don't think it will work correctly
for cross-compiled packages.
Do you have a better idea?
Best regards,
divoplade
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Wrapping an R script: how do I compose the R_LIBS_SITE environment variable?
2021-02-05 16:14 Wrapping an R script: how do I compose the R_LIBS_SITE environment variable? divoplade
@ 2021-02-06 13:53 ` zimoun
2021-02-06 15:28 ` Ricardo Wurmus
0 siblings, 1 reply; 7+ messages in thread
From: zimoun @ 2021-02-06 13:53 UTC (permalink / raw)
To: divoplade, help-guix, Ricardo Wurmus
Hi,
On Fri, 05 Feb 2021 at 17:14, divoplade <d@divoplade.fr> wrote:
> I am using guix to write R packages. For convenience, I created a small
> R script that does the job.
Is “guix import cran” not enough? What is the source of these R packages?
Well, could you be more specific about “using guix to write R packages”?
> To make this script work as-is, I wrapped it using wrap-program. wrap-
> program creates a shell script that sets up environment variables and
> then call the real script, because R needs to be able to find all the
> packages and dependencies. More specifically, I need to extend the
> R_LIBS_SITE environment variable to point to all the R dependencies of
> my package, as well as their recursive dependencies.
This seems the job of Guix.
> How do I compute that? I only care about R dependencies, so using the
> whole recursive dependency tree of my package seems too much.
Ricardo wrote a R helper:
<https://elephly.net/paste/1612619217.R.html>
Basically, it does more or less what “guix install” does but directly in
the R repl. Maybe it is what you want.
Hope that helps,
simon
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Wrapping an R script: how do I compose the R_LIBS_SITE environment variable?
2021-02-06 13:53 ` zimoun
@ 2021-02-06 15:28 ` Ricardo Wurmus
2021-02-07 0:24 ` divoplade
0 siblings, 1 reply; 7+ messages in thread
From: Ricardo Wurmus @ 2021-02-06 15:28 UTC (permalink / raw)
To: zimoun; +Cc: help-guix
zimoun <zimon.toutoune@gmail.com> writes:
> Ricardo wrote a R helper:
>
> <https://elephly.net/paste/1612619217.R.html>
>
> Basically, it does more or less what “guix install” does but directly in
> the R repl. Maybe it is what you want.
It also imports packages on the fly in case they don’t exist in Guix
yet.
--
Ricardo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Wrapping an R script: how do I compose the R_LIBS_SITE environment variable?
2021-02-06 15:28 ` Ricardo Wurmus
@ 2021-02-07 0:24 ` divoplade
2021-02-07 7:11 ` Ricardo Wurmus
0 siblings, 1 reply; 7+ messages in thread
From: divoplade @ 2021-02-07 0:24 UTC (permalink / raw)
To: Ricardo Wurmus, zimoun; +Cc: help-guix
[-- Attachment #1: Type: text/plain, Size: 891 bytes --]
Hello,
Sorry, I realize I was not clear enough.
Attached is an example of a script written in R that has non-trivial
recursive dependencies.
You can run the example as:
guix environment --ad-hoc --container -l package.scm -- hello
You will normally see something like:
$ guix environment --ad-hoc --container -l /tmp/package.scm -- hello
# A tibble: 10 x 2
x y
<int> <dbl>
1 1 1
2 2 4
3 3 9
4 4 16
5 5 25
6 6 36
7 7 49
8 8 64
9 9 81
10 10 100
sh: rm: command not found
If you look at the package definition, you see that I call wrap-program
in order to set the R_LIBS_SITE environment variable. The components of
R_LIBS_SITE is the R dependencies of my package, and their recursive R
dependencies. But I don't know how to get them.
I hope this example is better at explaining the problem.
[-- Attachment #2: package.scm --]
[-- Type: text/x-scheme, Size: 2051 bytes --]
(use-modules (guix packages)
(guix build-system trivial)
(guix gexp)
(gnu packages base)
(gnu packages bash)
(gnu packages statistics)
(gnu packages cran))
(package
(name "r-hello")
(version "0.0.0")
(source (plain-file "empty" ""))
(build-system trivial-build-system)
(arguments
'(#:modules ((guix build utils))
#:builder
(begin
(use-modules (guix build utils))
(let ((out (assoc-ref %outputs "out"))
(r-in (assoc-ref %build-inputs "r-minimal"))
(bash-in (assoc-ref %build-inputs "bash")))
(mkdir out)
(mkdir (string-append out "/bin"))
;; Bug? PATH is not set
(setenv "PATH" (string-append bash-in "/bin"))
(call-with-output-file (string-append out "/bin/hello")
(lambda (port)
(format port "#!~a/bin/Rscript
library (\"magrittr\")
data <- (tibble::tibble (x = 1:10)
%>% dplyr::mutate (y = x ^ 2))
print (data)
"
r-in)))
(chmod (string-append out "/bin/hello") #o755)
(wrap-program
(string-append out "/bin/hello")
`("R_LIBS_SITE" ":" =
,(map (lambda (r-package)
;; R_LIBS_SITE should point to the site-library
;; folder of the packages
(string-append (assoc-ref %build-inputs r-package)
"/site-library"))
;; Here are my R dependencies:
'("r-magrittr" "r-tibble" "r-dplyr"
;; However, running hello requires these recursive
;; dependencies. How am I supposed to know? What if
;; they change with future versions of my
;; dependencies?
"r-rlang" "r-vctrs" "r-r6" "r-generics" "r-glue"
"r-lifecycle" "r-ellipsis" "r-pillar" "r-crayon"
"r-pkgconfig" "r-tidyselect" "r-purrr" "r-cli"
"r-assertthat" "r-fansi" "r-utf8"))))))))
(native-inputs
`(("bash" ,bash)))
(inputs
`(("r-minimal" ,r-minimal)
("bash" ,bash)))
(propagated-inputs
`(("r-magrittr" ,r-magrittr)
("r-tibble" ,r-tibble)
("r-dplyr" ,r-dplyr)))
(synopsis "A script written in R")
(description "How can I list the recursive R dependencies?")
(home-page "http://example.com")
(license '...))
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Wrapping an R script: how do I compose the R_LIBS_SITE environment variable?
2021-02-07 0:24 ` divoplade
@ 2021-02-07 7:11 ` Ricardo Wurmus
2021-02-07 9:30 ` divoplade
0 siblings, 1 reply; 7+ messages in thread
From: Ricardo Wurmus @ 2021-02-07 7:11 UTC (permalink / raw)
To: divoplade; +Cc: help-guix
divoplade <d@divoplade.fr> writes:
> Attached is an example of a script written in R that has non-trivial
> recursive dependencies.
Why don’t you use the r-build-system here?
> If you look at the package definition, you see that I call wrap-program
> in order to set the R_LIBS_SITE environment variable. The components of
> R_LIBS_SITE is the R dependencies of my package, and their recursive R
> dependencies. But I don't know how to get them.
The r-build-system has a procedure “generate-site-path” to generate
R_LIBS_SITE.
--
Ricardo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Wrapping an R script: how do I compose the R_LIBS_SITE environment variable?
2021-02-07 7:11 ` Ricardo Wurmus
@ 2021-02-07 9:30 ` divoplade
2021-02-07 15:03 ` zimoun
0 siblings, 1 reply; 7+ messages in thread
From: divoplade @ 2021-02-07 9:30 UTC (permalink / raw)
To: Ricardo Wurmus; +Cc: help-guix
Hello,
Le dimanche 07 février 2021 à 08:11 +0100, Ricardo Wurmus a écrit :
> The r-build-system has a procedure “generate-site-path” to generate
> R_LIBS_SITE.
Thank you, I did not know about this function. It is not exported, but
I can copy it, or re-use the R_LIBS_SITE environment variable after the
install phase.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Wrapping an R script: how do I compose the R_LIBS_SITE environment variable?
2021-02-07 9:30 ` divoplade
@ 2021-02-07 15:03 ` zimoun
0 siblings, 0 replies; 7+ messages in thread
From: zimoun @ 2021-02-07 15:03 UTC (permalink / raw)
To: divoplade, Ricardo Wurmus; +Cc: help-guix
Hi,
On Sun, 07 Feb 2021 at 10:30, divoplade <d@divoplade.fr> wrote:
> Le dimanche 07 février 2021 à 08:11 +0100, Ricardo Wurmus a écrit :
>> The r-build-system has a procedure “generate-site-path” to generate
>> R_LIBS_SITE.
>
> Thank you, I did not know about this function. It is not exported, but
> I can copy it, or re-use the R_LIBS_SITE environment variable after the
> install phase.
The Guile modules are a bit mysterious for me but you can try:
(define generate-site-path
(@@ (guix build r-build-system) generate-site-path))
instead of copying.
Cheers,
simon
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-02-07 15:04 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-05 16:14 Wrapping an R script: how do I compose the R_LIBS_SITE environment variable? divoplade
2021-02-06 13:53 ` zimoun
2021-02-06 15:28 ` Ricardo Wurmus
2021-02-07 0:24 ` divoplade
2021-02-07 7:11 ` Ricardo Wurmus
2021-02-07 9:30 ` divoplade
2021-02-07 15:03 ` zimoun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).