setup: setup

install_sentiment.aiR Documentation



Install and Setup package

  envname = "r-sentiment-ai",
  method = c("auto", "virtualenv", "conda"),
  gpu = FALSE,
  python_version = "3.8.10",
  modules = list(numpy = "1.19.5", sentencepiece = "0.1.95", tensorflow = "2.4.1",
    tensorflow_hub = "0.12.0", `tensorflow-text` = "2.4.3"),
  fresh_install = TRUE,
  restart_session = TRUE,
  model = c("en.large", "multi.large", "en", "multi"),
  envname = "r-sentiment-ai",
  method = c("auto", "virtualenv", "conda"),
  silent = FALSE



The name, or full path, of the environment in which Python packages are to be installed. When NULL (the default), the active environment as set by the RETICULATE_PYTHON_ENV variable will be used; if that is unset, then the r-reticulate environment will be used.


Installation method. By default, "auto" automatically finds a method that will work in the local environment. Change the default to force a specific installation method. Note that the "virtualenv" method may not available on Windows due to a tensorflow issue. Note also that since this command runs without privilege the "system" method is available only on Windows.


Whether GPU should be enabled when installing TensorFlow


The requested Python version. Ignored when attempting to install with a Python virtual environment.


A list of modules needed for installing tensorflow. See details for more information. Only change this argument if you know what you are doing!


Whether to create the Python environment prior to installing the modules or to install everything in an existing environment (if one exists). Only change this argument if you know what you are doing! If the environment does not already exist, will create the environment first.


Whether to restart the R session after finishing installation. Only works on Rstudio.


Additional arguments passed to conda_install() or virtualenv_install().


path to tensorflow hub embedding model. default is both universal sentence encoder en (default) and multi.


logical - do you want to suppress console logging? Can't affect tensorflow/GPU/python/c++ output, unfortunately.


Sets up environment specific for The packages that it currently needs are as follows:

Module Version
python 3.8.10
numpy 1.19.5
tensorflow 2.4.1
tensorflow_hub 0.12.0
tensorflow-text 2.4.3
sentencepiece 0.1.95

Please do not change these unless you know what you are doing.

Note that it installs with like tensorflow::install_tensorflow and pip = TRUE


NULL this function simply installs the required python dependencies and default scoring models and pre-calculated embedding vectors.

python function to embed text can be returned, but is not necessary. embed_text() does this for you.

NULL this function checks if has been called successfully, if not, it is called.


Setting environments with reticulate is notoriously difficult. If the RETICULATE_PYTHON environment is set, then reticulate will not let you change the Python binary used (or the Python environment) using use_condaenv or use_virtualenv. This environment can be accidentally set in the following ways:

  1. If RETICULATE_PYTHON is in your .Renviron file or bash/zsh rc files. This is the most obvious place that this environment will be set.

  2. Using Project Options or Global Options under "Python>Python Interpreter". If this is set, then reticulate will almost always use this version of Python and will not let you change.

  3. If you have already loaded reticulate and have run py_config. Once a Python version/environment is instantiated, you will not be able to change it and will have to restart R.

  4. If you are in any project, at all! Currently (as of reticulate version 1.22), every project automatically sets the RETICULATE_PYTHON environment variable, either through the Global or Project Options or by using heuristics. If you are in an RStudio project, you must update Global/Project Options with the specific version/environment of Python that you want to use, or you will not be able to change it!

Manually setting the environment variable to NULL (using Sys.unsetenv("RETICULATE_PYTHON"), updating your Project/Global options going Tools>Project Options or Tools>Global Options and then select Python in the left menu bar and click the "Select" button to manually set the Python interpreter, and/or restarting your R session might fix the problem.

We know this is a pain, and we would like to fix this for you, but we are dependent on the RStudio/reticulate team to update how they determine the allowable Python versions/environments.


## Not run: = "r-sentiment-ai",
                     method  = "conda",
                     python_version = "3.8.10")   = "en.large",
                  envname = "r-sentiment-ai")

# if you run into an issue, follow the instructions/see the note and retry!

## End(Not run) documentation built on March 19, 2022, 2:15 a.m.