{"id":19949498,"url":"https://github.com/jtilly/r-conda-env","last_synced_at":"2026-04-18T04:01:42.344Z","repository":{"id":78160674,"uuid":"254102546","full_name":"jtilly/r-conda-env","owner":"jtilly","description":"Wrap Python code including its conda environment in an R Package","archived":false,"fork":false,"pushed_at":"2020-04-13T05:02:45.000Z","size":65,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-16T09:36:00.739Z","etag":null,"topics":["conda","interface","python","r","reproducibility","reticulate"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jtilly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-08T13:55:13.000Z","updated_at":"2020-04-22T12:50:13.000Z","dependencies_parsed_at":"2023-02-27T21:30:33.592Z","dependency_job_id":null,"html_url":"https://github.com/jtilly/r-conda-env","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jtilly/r-conda-env","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtilly%2Fr-conda-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtilly%2Fr-conda-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtilly%2Fr-conda-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtilly%2Fr-conda-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jtilly","download_url":"https://codeload.github.com/jtilly/r-conda-env/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtilly%2Fr-conda-env/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31955919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conda","interface","python","r","reproducibility","reticulate"],"created_at":"2024-11-13T00:45:25.186Z","updated_at":"2026-04-18T04:01:42.297Z","avatar_url":"https://github.com/jtilly.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n# r-conda-env\n\n\u003c!-- badges: start --\u003e\n\n[![Travis build\nstatus](https://travis-ci.org/jtilly/r-conda-env.svg?branch=master)](https://travis-ci.org/jtilly/r-conda-env)\n\u003c!-- badges: end --\u003e\n\nR-Package = conda environment wrapped model\n\nThis package allows you to ship and deploy machine learning models built\nin Python using an R package.\n\nSay you have a Python model that works in one specific conda environment\nand you want to make it accessible to R users via reticulate. How do you\ngo about doing that?\n\nThis proof of concept R-package comes with a fully specified conda\nenvironment that will be created when the R package is installed. All\nPython code inside this package will then be run in this conda\nenvironment. We can ship several models in the same R package as long as\nthey share their conda environment. If two models do not share their\nconda environment, we ship them in separate R packages.\n\n## Install\n\nYou need to have conda installed on your system and reticulate must be\nable to [find\nit](https://rstudio.github.io/reticulate/reference/conda-tools.html#finding-conda).\n\n``` r\n# install.packages(\"remotes\")\nremotes::install_github(\"jtilly/r-conda-env\")\n```\n\n## Usage\n\n``` r\nlibrary(rcondaenv)\ncreate_package_env()\n#\u003e Creating conda environment now.\n#\u003e Environment 2f0409c2f60c564607d28c44c8edc52c already exists. Removing it first...\n#\u003e Created conda environment 2f0409c2f60c564607d28c44c8edc52c\ndf \u003c- tibble::tribble(\n  ~x, ~y, ~z,\n  \"a\", 2, 3.6,\n  \"b\", 1, 8.5\n)\npython_model_predict(df)\n#\u003e [1] 0 1\ncheck_pandas_version()\n#\u003e [1] \"The installed Pandas version is 1.0.3\"\n```\n\n## Details\n\n  - The conda requirements are defined in `inst/conda-requirements.txt`\n    and installed with the R Package.\n    \n        python=3.8.2=he5300dc_5_cpython\n        pandas=1.0.3=py38hcb8c335_0\n        numpy=1.18.1=py38h8854b6b_1\n    \n    Package versions are currently pinned. There’s an unpinned version\n    for non-Linux systems.\n\n  - Arbitrary Python code can be shipped with the package. Currently,\n    there’s only one file `inst/model.py`:\n    \n    ``` python\n    import pandas as pd\n    \n    def predict(df):\n      \"\"\"Trivial predict function that returns a sequence 0, 1, ..., n-1.\"\"\"\n      return df.reset_index(drop=True).index.astype(float)\n    \n    def check_pandas_version():\n      return(f\"The installed Pandas version is {pd.__version__}\")\n    ```\n\n  - The reticulate calls are in `R/predict.R`.\n\n  - We overcome the problem that you cannot use reticulate to interface\n    with different Python executables within the same R session (see\n    [this\n    comment](https://github.com/rstudio/reticulate/issues/27#issuecomment-512256949))\n    by running the reticulate call on a different worker (via the\n    `parallel` package - both `PSOCK` and `FORK` work here). This comes\n    with overhead, both for setting up the\n    [cluster](https://developer.r-project.org/Blog/public/2020/03/17/socket-connections-update/index.html)\n    and for serializing the data and communicating with the worker,\n    which may or may not be tolerable depending on your use case.\n\n## Performance\n\nA benchmark is provided for a data set with 10 numerical columns, 10\nstring columns, and 10 date columns. `encapsulate` uses the little hack\nthat allows us to use reticulate with different Python executables in\nthe same R session. `do_not_encapsulate` goes straight from the user’s R\nsession to reticulate.\n\n``` r\nset_cluster_type(\"FORK\")\nresults \u003c- bench(n = 1e6)\n#\u003e Running with:\n#\u003e         n\n#\u003e 1       1\n#\u003e 2      10\n#\u003e 3     100\n#\u003e 4    1000\n#\u003e 5   10000\n#\u003e 6  100000\n#\u003e 7 1000000\nknitr::kable(results[c(\"expression\", \"n\", \"median\")])\n```\n\n| expression               |     n |   median |\n| :----------------------- | ----: | -------: |\n| encapsulate(df)          | 1e+00 | 542.29ms |\n| do\\_not\\_encapsulate(df) | 1e+00 | 459.25ms |\n| encapsulate(df)          | 1e+01 | 510.14ms |\n| do\\_not\\_encapsulate(df) | 1e+01 | 465.09ms |\n| encapsulate(df)          | 1e+02 | 500.33ms |\n| do\\_not\\_encapsulate(df) | 1e+02 | 464.31ms |\n| encapsulate(df)          | 1e+03 | 566.11ms |\n| do\\_not\\_encapsulate(df) | 1e+03 | 470.98ms |\n| encapsulate(df)          | 1e+04 | 614.53ms |\n| do\\_not\\_encapsulate(df) | 1e+04 | 532.51ms |\n| encapsulate(df)          | 1e+05 |    1.91s |\n| do\\_not\\_encapsulate(df) | 1e+05 |    1.17s |\n| encapsulate(df)          | 1e+06 |   12.01s |\n| do\\_not\\_encapsulate(df) | 1e+06 |    7.52s |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjtilly%2Fr-conda-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjtilly%2Fr-conda-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjtilly%2Fr-conda-env/lists"}