Skip to content
Merged
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
Expand Up @@ -114,6 +114,7 @@ celerybeat.pid

# Environments
.env
.Renviron
.venv
env/
venv/
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ version:
@:$(call check_defined, tag, new semver version tag to use on pyproject.toml)
@poetry version $(tag)
@echo "__version__ = \"$$(poetry version -s)\"" > validmind/__version__.py
@sed -i '' 's/^Version: .*/Version: '"$$(poetry version -s)"'/' r/validmind/DESCRIPTION
@echo "Version updated to $$(poetry version -s)"
@echo "Commiting changes to pyproject.toml and __version__.py with message: $$(poetry version -s)"
@git add pyproject.toml validmind/__version__.py
@echo "Commiting changes to pyproject.toml, __version__.py and r/validmind/DESCRIPTION with message: $$(poetry version -s)"
@git add pyproject.toml validmind/__version__.py r/validmind/DESCRIPTION
@git commit -m "$$(poetry version -s)"

generate-test-id-types:
Expand Down
58 changes: 54 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,71 @@ You can install the `transformers`, `torch` and `openai` dependencies using the
poetry install --extras llm
```

### Installing R dependencies
### Setting up R support

If you want to use the R support that is provided by the ValidMind Library, you must have R installed on your machine. You can download R from <https://cran.r-project.org/>. On a Mac, you can install R using Homebrew:
#### 1. Install R

You can download R from <https://cran.r-project.org/>. On macOS, the easiest way is via Homebrew:

```bash
brew install r
```

Once you have R installed, install the `r-support` extra to install the necessary dependencies for R by running:
#### 2. Install Python dependencies

Install `rpy2` so the Python library can interface with R models. On macOS, you may need to build from source to match your R version:

```bash
poetry install
# Try the standard install first
pip install rpy2

# If you get R library loading errors, rebuild against your installed R:
R_HOME=$(Rscript -e 'cat(R.home())') pip install --no-binary :all: --force-reinstall rpy2
```

#### 3. Install R packages

Open R (type `R` in your terminal) and install the required packages:

```r
install.packages(c("reticulate", "dplyr", "caTools", "knitr", "glue", "plotly", "htmltools", "rmarkdown", "DT", "base64enc"))
```

Then install the ValidMind R package from source:

```r
install.packages("r/validmind", repos = NULL, type = "source")
```

#### 4. Set up VS Code / Cursor for R

No RStudio required. Install the **R extension** (`REditorSupport.r`) in VS Code or Cursor:

1. Open Extensions (`Cmd+Shift+X`) and search for "R"
2. Install the **R** extension by REditorSupport
3. Optionally install the `languageserver` R package for autocomplete: `install.packages("languageserver")`

With the extension installed:
- Open `.Rmd` files and run chunks with `Cmd+Shift+Enter`
- Render full documents with `Cmd+Shift+K`
- Use the R terminal panel for interactive sessions

Alternatively, you can run R notebooks as Jupyter notebooks by installing the R kernel:

```r
install.packages("IRkernel")
IRkernel::installspec()
```

Then create/open `.ipynb` files in VS Code and select the R kernel.

#### 5. Run the quickstart notebooks

Launch R from the repository root (so dataset paths resolve correctly) and run through the notebooks in `notebooks/code_sharing/r/`:

- `quickstart_model_documentation.Rmd` — model documentation workflow
- `quickstart_model_validation.Rmd` — model validation workflow

### Versioning

Make sure you bump the package version before merging a PR with the following command:
Expand Down
6 changes: 1 addition & 5 deletions notebooks/code_sharing/r/r_custom_tests.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,11 @@ Get your code snippet:
Next, replace this placeholder with your own code snippet:

```{r}
# Find the path to your Python runtime by running `python -V` in your terminal
# python_version <- "<path_to_python_version>"

vm_r <- vm(
api_host = "https://api.prod.validmind.ai/api/v1/tracking",
api_key = "...",
api_secret = "...",
model = "...",
python_version = python_version
model = "..."
)
```

Expand Down
10 changes: 6 additions & 4 deletions notebooks/code_sharing/r/r_customer_churn_demo.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ We will train a sample model and demonstrate the following documentation functio
```{r setup, include=FALSE}
library(reticulate)

python_version <- "<path_to_python_version>"
python_version <- Sys.getenv("VALIDMIND_PYTHON", Sys.which("python"))
if (nchar(python_version) > 0 && !startsWith(python_version, "/")) {
python_version <- file.path(getwd(), python_version)
}
use_python(python_version)

library(validmind)
Expand Down Expand Up @@ -64,11 +67,10 @@ The code snippet can be copied and pasted directly in the cell below to initiali

```{r}
vm_r <- vm(
api_host="https://app.prod.validmind.ai/api/v1/tracking",
api_key="<your_api_key_here>",
api_secret="<your_api_secret_here>",
model="<your_model_id_here>",
python_version=python_version,
api_host="https://app.prod.validmind.ai/api/v1/tracking"
model="<your_model_id_here>"
)
```

Expand Down
10 changes: 6 additions & 4 deletions notebooks/code_sharing/r/r_customer_churn_demo_xgboost.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ We will train a sample model and demonstrate the following documentation functio
```{r setup, include=FALSE}
library(reticulate)

python_version <- "<path_to_python_version>"
python_version <- Sys.getenv("VALIDMIND_PYTHON", Sys.which("python"))
if (nchar(python_version) > 0 && !startsWith(python_version, "/")) {
python_version <- file.path(getwd(), python_version)
}
use_python(python_version)

library(validmind)
Expand Down Expand Up @@ -65,11 +68,10 @@ The code snippet can be copied and pasted directly in the cell below to initiali

```{r}
vm_r <- vm(
api_host="https://app.prod.validmind.ai/api/v1/tracking",
api_key="<your_api_key_here>",
api_secret="<your_api_secret_here>",
model="<your_model_id_here>",
python_version=python_version,
api_host="https://app.prod.validmind.ai/api/v1/tracking"
model="<your_model_id_here>"
)
```

Expand Down
10 changes: 6 additions & 4 deletions notebooks/code_sharing/r/r_mortality_demo.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ The <b>features</b> used in the mortality model are:
```{r setup, include=FALSE}
library(reticulate)

python_version <- "<path_to_python_version>"
python_version <- Sys.getenv("VALIDMIND_PYTHON", Sys.which("python"))
if (nchar(python_version) > 0 && !startsWith(python_version, "/")) {
python_version <- file.path(getwd(), python_version)
}
use_python(python_version)

library(magrittr) # needs to be run every time you start R and want to use %>%
Expand Down Expand Up @@ -156,11 +159,10 @@ initialize the ValidMind Library when run:

```{r}
vm_r <- vm(
api_host="https://app.prod.validmind.ai/api/v1/tracking",
api_key="<your_api_key_here>",
api_secret="<your_api_secret_here>",
model="<your_project_id_here>",
python_version=python_version,
api_host="https://app.prod.validmind.ai/api/v1/tracking"
model="<your_model_id_here>"
)
```

Expand Down
10 changes: 6 additions & 4 deletions notebooks/code_sharing/r/r_time_series_data_validation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ Finally, define and **configure** the specific use case we are working on by set
```{r setup, include=FALSE}
library(reticulate)

python_version <- "<path_to_python_version>"
python_version <- Sys.getenv("VALIDMIND_PYTHON", Sys.which("python"))
if (nchar(python_version) > 0 && !startsWith(python_version, "/")) {
python_version <- file.path(getwd(), python_version)
}
use_python(python_version)

library(validmind)
Expand Down Expand Up @@ -58,11 +61,10 @@ The code snippet can be copied and pasted directly in the cell below to initiali

```{r}
vm_r <- vm(
api_host="https://app.prod.validmind.ai/api/v1/tracking",
api_key="<your_api_key_here>",
api_secret="<your_api_secret_here>",
model="<your_project_id_here>",
python_version=python_version,
api_host="https://app.prod.validmind.ai/api/v1/tracking"
model="<your_model_id_here>"
)
```

Expand Down
14 changes: 8 additions & 6 deletions notebooks/code_sharing/r/r_time_series_model_validation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ Finally, define and **configure** the specific use case we are working on by set
```{r setup, include=FALSE}
library(reticulate)

python_version <- "/Users/erichare/.pyenv/versions/3.10.10/bin/python"
python_version <- Sys.getenv("VALIDMIND_PYTHON", Sys.which("python"))
if (nchar(python_version) > 0 && !startsWith(python_version, "/")) {
python_version <- file.path(getwd(), python_version)
}
use_python(python_version)

library(magrittr) # needs to be run every time you start R and want to use %>%
Expand Down Expand Up @@ -75,11 +78,10 @@ The code snippet can be copied and pasted directly in the cell below to initiali

```{r}
vm_r <- vm(
api_key="b34dfe4dcb5491212be3eefe77c85cd6",
api_secret="40f8d2d583baa9e730a7f8872dd57e2f4657c7918c13fa259ba7ccda8a60e858",
model="clmp6k8e800ds19mot0zu8o34",
python_version=python_version,
api_host="https://app.prod.validmind.ai/api/v1/tracking"
api_host="https://app.prod.validmind.ai/api/v1/tracking",
api_key="<your_api_key_here>",
api_secret="<your_api_secret_here>",
model="<your_model_id_here>"
)
```

Expand Down
Loading
Loading