-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature suggestion: Inline anotations and command line #286
Comments
Hey @jrosell thanks for your ideas. # env.R
rix::rix(
r_ver = "4.3.2",
r_pkgs = "data.table",
overwrite = TRUE,
project_path = "./my_proj_subdir"
) Run that Then use a custom bash , #!/usr/bin/env nix-shell
#! nix-shell -i bash --pure default.nix
Rscript \
--no-site-file \
--no-environ \
--no-restore \
${1} And just ./nix-rscript.sh data-visualize.R |
To sum up, maybe like a littler script helper. https://nix.dev/tutorials/first-steps/reproducible-scripts.html is a nice ref. |
Well, the goal is to have rix anotations at script level so one can run something like: rix run script.R In Python one can do inline anotations and run: uv run script.py |
Well, these are at least two pair of shoes. I like those inline annotations. It needs a lot on top of the nix-Rscript runner. Tooling in nix? Nix ensures reproducibility via output hashes and based on inputs in the expression supplied. Currently, rix boilerplating assumes one fixed nixpkgs revisions/git hashes for specific packages, but in principle it could be extended to multiple. There is quite a bit of tooling needed so we can leverage renv lockfile to-nix work (see #5 ) . Ideas and PRs are very welcome. Wanna join the Nixpkgs R matrix channel? Could be a good place to brainstorm, too. |
Here is what I have. It works in Ubuntu: https://github.com/jrosell/rix-run |
that's really cool, I must admit that I didn't really understand what you meant but now that I see it, it's really nice! How would you like to move forward with this? Would you like to have it included into rix? We are in the process of submitting to CRAN very soon so now wouldn't be the right moment to add a completely new feature, however if you want to continue to work on it feel free, and we could merge a PR for a next release. |
I think that the rix-run script belongs to rix, but I belive that the script should work fine on more systems. So, we can wait. |
To keep you update, it turns out that rix-run plays well with targets script file too. I really like the ability to have multiple target scripts in the same project. https://github.com/jrosell/rix-run?tab=readme-ov-file#targets-single-file |
I thought about this idea and I think it could be taken further using {processx} as {callr} do. I imagine something like this for testing same function on diferent R versions using nix shell processes. bench::mark( What do you think? |
Running R functions in different Nix R environments is exactly what Lines 284 to 292 in 287e8bd
https://docs.ropensci.org/rix/articles/z-advanced-topic-running-r-or-shell-code-in-nix-from-r.html We do it via {sys} and have some safe defaults to run code it different nix shells, with proper recursive detection of globals etc. The approach really works well and I don't think it's necessary to have duplicate functionality. For functionality under the hood, see https://github.com/ropensci/rix/blob/main/R/with_nix_helpers.R Cheers, |
Thanks, Philipp. I tested it a bit and I get some weird results with this approach. I assume it's because it doesn't make sense to benchmark with less than 10s precision with this implementation.
|
Yes, exactly, it doesn't make sense to benchmark, because there is a serialization/deserialization overhead (including detecting and assigning globals recursively before), the time to invoke |
I have currently on my aarch64 MacbookM2 about 2.5s median time (my rocky linux in my home network is currently disconnected from ssh access). Had to switch to to benchmark_dummy <- \(){
invisible(NULL)
}
benchmark_memCompress <- \(){
txt <- readLines(file.path(R.home(), "COPYING"))
for (i in 1:100) {
memCompress(txt, "g")
}
invisible(NULL)
}
results_r <- bench::mark(
dummy = {
benchmark_dummy()
},
memCompress ={
benchmark_memCompress()
},
check = FALSE,
memory = FALSE,
min_time = 10
)
r_latest_path <- file.path("latest")
r_3_6_3_path <- file.path("3.6.3")
results_r[, c("expression", "median")]
# Configuring and initial set up of the two environments
# R 3.6.3 is not available for aarch64-darwin,will not build because at that
# time nixpkgs was not yet supporting the Apple Silicon architecture
# rix::rix(r_ver = "3.6.3", project_path = r_3_6_3_path, overwrite = TRUE)
# rix::nix_build(project_path = r_3_6_3_path)
rix::rix(r_ver = "latest", project_path = r_latest_path, overwrite = TRUE)
rix::nix_build(project_path = r_latest_path)
# Get the fastest time
results_dummy <- bench::mark(
# old_dummy = {
# rix::with_nix(benchmark_dummy, project_path = "/tmp/R/3.6.3", program = "R")
# },
new_dummy ={
rix::with_nix(benchmark_dummy, project_path = r_latest_path, program = "R")
},
check = FALSE,
memory = FALSE,
filter_gc = FALSE,
min_time = 10
)
benchmark_new <- microbenchmark::microbenchmark(
new_dummy ={
rix::with_nix(benchmark_dummy, project_path = r_latest_path, program = "R")
},
times = 20
) Where i get > benchmark_new
Unit: seconds
expr min lq mean median uq max neval
new_dummy 2.379217 2.4867 2.54477 2.503232 2.584663 2.785343 20 whatever it will be, you will have the overhead of |
I'm not sure if I understand well what you said in the last paragraph. Do you mean to run two separate benchmarks in two diferent scripts? I think I can try it with my rix-run tool. It could make sense. |
I tried the {rix} package today and I think about two features that could make it more awesome for R development.
Let me give an example here.
data-visualize.R file
rix file
The first feature is a rix command line tool. For example, one can run: bash rix $(pwd)/data-visualize.R to generate the ''penguin-plot.png' plot.
The second feature is inline script metadata for R like python already have.
If you look at my code for the rix file I already set the rix R command in the nix-shell call but I think it could be anotated some way in the file to be run.
Let me know what you think.
The text was updated successfully, but these errors were encountered: