Skip to contents

rxp_py Creates a Nix expression running a Python function

Usage

rxp_py(name, py_expr, additional_files = "", nix_env = "default.nix")

Arguments

name

Symbol, name of the derivation.

additional_files

Character vector, additional files to include. Custom functions must go into a script called "functions.R", and additional files that need to be accessible during the build process can be named anything.

nix_env

Character, path to the Nix environment file, default is "default.nix".

expr

R code to generate the expression.

Value

A list with elements: name, the name of the derivation, snippet, the Nix boilerplate code, type, additional_files and nix_env.

Details

At a basic level, rxp_py(mtcars_am, "mtcars.filter(polars.col('am') == 1)") is equivalent to mtcars_am = mtcars.filter(polars.col('am') == 1). rxp_py()generates the required Nix boilerplate to output a so-called "derivation" in Nix jargon. A Nix derivation is a recipe that defines how to create an output (in this casemtcars_am`) including its dependencies, build steps, and output paths.

Examples

rxp_py(mtcars_pl_am, py_expr = "mtcars_pl.filter(polars.col('am') == 1).to_pandas()")
#> $name
#> [1] "mtcars_pl_am"
#> 
#> $snippet
#> [1] "  mtcars_pl_am = makePyDerivation {\n    name = \"mtcars_pl_am\";\n    buildInputs = defaultBuildInputs;\n    configurePhase = defaultConfigurePhase;\n    buildPhase = ''\n      python -c \"\nexec(open('libraries.py').read())\nexec('mtcars_pl_am = mtcars_pl.filter(polars.col(\\'am\\') == 1).to_pandas()')\nwith open('mtcars_pl_am.pickle', 'wb') as f: pickle.dump(globals()['mtcars_pl_am'], f)\"\n    '';\n  };"
#> 
#> $type
#> [1] "rxp_py"
#> 
#> $additional_files
#> [1] ""
#> 
#> $nix_env
#> [1] "default.nix"
#>