Notes on: How to use (Sci)BERT and PyTorch from within R

First, follow the steps described here, to set up an Rstudio Project with and virtual environment (virtualenv) for python.

Alternatively, execute the following commands in your Terminal, within the project folder.

pip install virtualenv
virtualenv python
source python/bin/activate

And create an .RProfile file in your project folder with the following content

Sys.setenv(RETICULATE_PYTHON = "py_env/python/bin/python")

Next, you want to install RUST, since it is needed to build the tokenizer used in the transformers library.

curl --proto '=https' --tlsv1.2 -sSf | sh
source $HOME/.cargo/env

And install the transformers and torch libraries:

pip install transformers torch