Skip to content
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

R interface #60

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
.ipynb_checkpoints
__pycache__
.Rproj.user
2 changes: 2 additions & 0 deletions r-interface/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.quarto/
*html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should add _freeze directory in .gitignore, and also remove it from the git repository.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should add reticulate/reticulate_files/libs directory in .gitignore, and also remove it from the git repository.

133 changes: 133 additions & 0 deletions r-interface/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@

<!-- README.md is generated from README.qmd. Please edit that file -->

# Setup instructions for using GUDHI from R

<!-- badges: start -->
<!-- badges: end -->

## The [**reticulate**](https://rstudio.github.io/reticulate/) package

The [**reticulate**](https://rstudio.github.io/reticulate/) package
provides a comprehensive set of tools for interoperability between
Python and R. The package includes facilities for:

- Calling Python from R in a variety of ways including R Markdown,
sourcing Python scripts, importing Python modules, and using Python
interactively within an R session.
- Translation between R and Python objects (for example, between R and
Pandas data frames, or between R matrices and NumPy arrays).
- Flexible binding to different versions of Python including virtual
environments and Conda environments.

[**reticulate**](https://rstudio.github.io/reticulate/) embeds a Python
session within your R session, enabling seamless, high-performance
interoperability. If you are an R developer that uses Python for some of
your work or a member of data science team that uses both languages,
[**reticulate**](https://rstudio.github.io/reticulate/) can dramatically
streamline your workflow.

## Bring GUDHI into R

- First, you’ll want to install and load the
[**reticulate**](https://rstudio.github.io/reticulate/) package into
your session:

``` r
# install.packages("reticulate")
library(reticulate)
```

- Next, the fastest way to get you set up to use Python from R with
[**reticulate**](https://rstudio.github.io/reticulate/) is to use
the `install_miniconda()` utility function which is included in the
[**reticulate**](https://rstudio.github.io/reticulate/) package. In
details, use something like:

``` r
install_miniconda()
```

- Next, it is recommended that you create a virtual conda environment
in which you’ll install all required Python packages. This can be
achieved using the `reticulate::conda_create()` function as follows:

``` r
version <- "3.9.6"
conda_create("r-reticulate", python_version = version)
```

- Next, you can seamlessly install all the Python packages you need by
calling the `conda_install()` function. For instance, to use Gudhi,
you would do something like:

``` r
conda_install("scikit-learn", envname = "r-reticulate")
conda_install("gudhi", envname = "r-reticulate")
```

This is a setup that you ought to do only once (unless you want to
change your Python version for some reason).

If you want to check your Python configuration, you can do:

``` r
py_config()
#> python: /Users/stamm-a/Library/r-miniconda/envs/r-reticulate/bin/python3.9
#> libpython: /Users/stamm-a/Library/r-miniconda/envs/r-reticulate/lib/libpython3.9.dylib
#> pythonhome: /Users/stamm-a/Library/r-miniconda/envs/r-reticulate:/Users/stamm-a/Library/r-miniconda/envs/r-reticulate
#> version: 3.9.6 | packaged by conda-forge | (default, Jul 11 2021, 03:36:15) [Clang 11.1.0 ]
#> numpy: /Users/stamm-a/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/numpy
#> numpy_version: 1.22.4
#>
#> NOTE: Python version was forced by RETICULATE_PYTHON
```

# Organisation

## File hierarchy

This folder contains a number of [Quarto](https://quarto.org) documents
contributed with the purpose of showing how
[`R`](https://www.r-project.org) can be used to enhance statistical
analysis of topological data produced via
[Gudhi](https://gudhi.inria.fr). Each tutorial is hosted in its own
folder which is organised as follows:

- The Quarto document with extension `.qmd` which is the main file
that a developer is supposed to contribute. In this document, there
is a YAML header in which the contributor can specify various output
formats by adding

``` yaml
#| eval: false
format:
html: default
gfm: default
pdf: default
```

The complete list of possible output formats:
<https://quarto.org/docs/output-formats/all-formats.html>.

- A Github-flavored markdown (GMF) document with extension `.md` which
enables nice visualization of the notebook directly in the Github
web interface.

- A folder containing useful libs and resources to display the GMF
document.

## Contributing

If you want to contribute, you should

1. Fork the `TDA-tutorials` repo
2. Open the RStudio project in
`TDA-tutorials/r-interface/r-interface.Rproj`.
3. When opened in RStudio, the working directory should now be
`TDA-tutorials/r-interface/` in which you can now create a folder
with evocative name to put the Quarto document describing the
analysis you want to share.
- Note: you can use the same YAML header as in
`reticulate/reticulate.qmd` as a number of presets for rendering
are made into the `_quarto.yml` file.
142 changes: 142 additions & 0 deletions r-interface/README.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
---
format: gfm
toc: false
---

<!-- README.md is generated from README.qmd. Please edit that file -->

```{r}
#| label: setup
#| include: false
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

# Setup instructions for using GUDHI from R

<!-- badges: start -->

<!-- badges: end -->

## The [**reticulate**](https://rstudio.github.io/reticulate/) package

The [**reticulate**](https://rstudio.github.io/reticulate/) package
provides a comprehensive set of tools for interoperability between
Python and R. The package includes facilities for:

- Calling Python from R in a variety of ways including R Markdown,
sourcing Python scripts, importing Python modules, and using Python
interactively within an R session.
- Translation between R and Python objects (for example, between R and
Pandas data frames, or between R matrices and NumPy arrays).
- Flexible binding to different versions of Python including virtual
environments and Conda environments.

[**reticulate**](https://rstudio.github.io/reticulate/) embeds a Python
session within your R session, enabling seamless, high-performance
interoperability. If you are an R developer that uses Python for some of
your work or a member of data science team that uses both languages,
[**reticulate**](https://rstudio.github.io/reticulate/) can dramatically
streamline your workflow.

## Bring GUDHI into R

- First, you'll want to install and load the
[**reticulate**](https://rstudio.github.io/reticulate/) package into
your session:

```{r}
# install.packages("reticulate")
library(reticulate)
```

- Next, the fastest way to get you set up to use Python from R with
[**reticulate**](https://rstudio.github.io/reticulate/) is to use
the `install_miniconda()` utility function which is included in the
[**reticulate**](https://rstudio.github.io/reticulate/) package. In
details, use something like:

```{r}
#| eval: false
install_miniconda()
```

- Next, it is recommended that you create a virtual conda environment
in which you'll install all required Python packages. This can be
achieved using the `reticulate::conda_create()` function as follows:

```{r}
#| eval: false
version <- "3.9.6"
conda_create("r-reticulate", python_version = version)
```

- Next, you can seamlessly install all the Python packages you need by
calling the `conda_install()` function. For instance, to use Gudhi,
you would do something like:

```{r}
#| eval: false
conda_install("scikit-learn", envname = "r-reticulate")
conda_install("gudhi", envname = "r-reticulate")
```

This is a setup that you ought to do only once (unless you want to
change your Python version for some reason).

If you want to check your Python configuration, you can do:

```{r}
py_config()
```

# Organisation

## File hierarchy

This folder contains a number of [Quarto](https://quarto.org) documents
contributed with the purpose of showing how
[`R`](https://www.r-project.org) can be used to enhance statistical
analysis of topological data produced via
[Gudhi](https://gudhi.inria.fr). Each tutorial is hosted in its own
folder which is organised as follows:

- The Quarto document with extension `.qmd` which is the main file
that a developer is supposed to contribute. In this document, there
is a YAML header in which the contributor can specify various output
formats by adding

``` yaml
#| eval: false
format:
html: default
gfm: default
pdf: default
```

The complete list of possible output formats:
<https://quarto.org/docs/output-formats/all-formats.html>.

- A Github-flavored markdown (GMF) document with extension `.md` which
enables nice visualization of the notebook directly in the Github
web interface.

- A folder containing useful libs and resources to display the GMF
document.

## Contributing

If you want to contribute, you should

1. Fork the `TDA-tutorials` repo
2. Open the RStudio project in
`TDA-tutorials/r-interface/r-interface.Rproj`.
3. When opened in RStudio, the working directory should now be
`TDA-tutorials/r-interface/` in which you can now create a folder
with evocative name to put the Quarto document describing the
analysis you want to share.
- Note: you can use the same YAML header as in
`reticulate/reticulate.qmd` as a number of presets for rendering
are made into the `_quarto.yml` file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could add somewhere in this global r-interface README a link to the reticulate/reticulate.md

16 changes: 16 additions & 0 deletions r-interface/_freeze/README/execute-results/md.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"hash": "9629af67199513e45263219d8338c33e",
"result": {
"markdown": "---\nformat: gfm\ntoc: false\n---\n\n\n<!-- README.md is generated from README.qmd. Please edit that file -->\n\n\n\n\n\n# Setup instructions for using GUDHI from R\n\n<!-- badges: start -->\n\n<!-- badges: end -->\n\n## The [**reticulate**](https://rstudio.github.io/reticulate/) package\n\nThe [**reticulate**](https://rstudio.github.io/reticulate/) package\nprovides a comprehensive set of tools for interoperability between\nPython and R. The package includes facilities for:\n\n- Calling Python from R in a variety of ways including R Markdown,\n sourcing Python scripts, importing Python modules, and using Python\n interactively within an R session.\n- Translation between R and Python objects (for example, between R and\n Pandas data frames, or between R matrices and NumPy arrays).\n- Flexible binding to different versions of Python including virtual\n environments and Conda environments.\n\n[**reticulate**](https://rstudio.github.io/reticulate/) embeds a Python\nsession within your R session, enabling seamless, high-performance\ninteroperability. If you are an R developer that uses Python for some of\nyour work or a member of data science team that uses both languages,\n[**reticulate**](https://rstudio.github.io/reticulate/) can dramatically\nstreamline your workflow.\n\n## Bring GUDHI into R\n\n- First, you'll want to install and load the\n [**reticulate**](https://rstudio.github.io/reticulate/) package into\n your session:\n\n\n ::: {.cell}\n \n ```{.r .cell-code}\n # install.packages(\"reticulate\")\n library(reticulate)\n ```\n :::\n\n\n- Next, the fastest way to get you set up to use Python from R with\n [**reticulate**](https://rstudio.github.io/reticulate/) is to use\n the `install_miniconda()` utility function which is included in the\n [**reticulate**](https://rstudio.github.io/reticulate/) package. In\n details, use something like:\n\n\n ::: {.cell}\n \n ```{.r .cell-code}\n install_miniconda()\n ```\n :::\n\n\n- Next, it is recommended that you create a virtual conda environment\n in which you'll install all required Python packages. This can be\n achieved using the `reticulate::conda_create()` function as follows:\n\n\n ::: {.cell}\n \n ```{.r .cell-code}\n version <- \"3.9.6\"\n conda_create(\"r-reticulate\", python_version = version)\n ```\n :::\n\n\n- Next, you can seamlessly install all the Python packages you need by\n calling the `conda_install()` function. For instance, to use Gudhi,\n you would do something like:\n\n\n ::: {.cell}\n \n ```{.r .cell-code}\n conda_install(\"scikit-learn\", envname = \"r-reticulate\")\n conda_install(\"gudhi\", envname = \"r-reticulate\")\n ```\n :::\n\n\nThis is a setup that you ought to do only once (unless you want to\nchange your Python version for some reason).\n\nIf you want to check your Python configuration, you can do:\n\n\n::: {.cell}\n\n```{.r .cell-code}\npy_config()\n#> python: /Users/stamm-a/Library/r-miniconda/envs/r-reticulate/bin/python3.9\n#> libpython: /Users/stamm-a/Library/r-miniconda/envs/r-reticulate/lib/libpython3.9.dylib\n#> pythonhome: /Users/stamm-a/Library/r-miniconda/envs/r-reticulate:/Users/stamm-a/Library/r-miniconda/envs/r-reticulate\n#> version: 3.9.6 | packaged by conda-forge | (default, Jul 11 2021, 03:36:15) [Clang 11.1.0 ]\n#> numpy: /Users/stamm-a/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/numpy\n#> numpy_version: 1.22.4\n#> \n#> NOTE: Python version was forced by RETICULATE_PYTHON\n```\n:::\n\n\n# Organisation\n\n## File hierarchy\n\nThis folder contains a number of [Quarto](https://quarto.org) documents\ncontributed with the purpose of showing how\n[`R`](https://www.r-project.org) can be used to enhance statistical\nanalysis of topological data produced via\n[Gudhi](https://gudhi.inria.fr). Each tutorial is hosted in its own\nfolder which is organised as follows:\n\n- The Quarto document with extension `.qmd` which is the main file\n that a developer is supposed to contribute. In this document, there\n is a YAML header in which the contributor can specify various output\n formats by adding\n\n ``` yaml\n #| eval: false\n format:\n html: default\n gfm: default\n pdf: default\n ```\n\n The complete list of possible output formats:\n <https://quarto.org/docs/output-formats/all-formats.html>.\n\n- A Github-flavored markdown (GMF) document with extension `.md` which\n enables nice visualization of the notebook directly in the Github\n web interface.\n\n- A folder containing useful libs and resources to display the GMF\n document.\n\n## Contributing\n\nIf you want to contribute, you should\n\n1. Fork the `TDA-tutorials` repo\n2. Open the RStudio project in\n `TDA-tutorials/r-interface/r-interface.Rproj`.\n3. When opened in RStudio, the working directory should now be\n `TDA-tutorials/r-interface/` in which you can now create a folder\n with evocative name to put the Quarto document describing the\n analysis you want to share.\n - Note: you can use the same YAML header as in\n `reticulate/reticulate.qmd` as a number of presets for rendering\n are made into the `_quarto.yml` file.\n",
"supporting": [
"README_files"
],
"filters": [
"rmarkdown/pagebreak.lua"
],
"includes": {},
"engineDependencies": {},
"preserve": {},
"postProcess": true
}
}
Loading