This vignette describes the three different ways to initialize the R session’s connection to Python using the rMIDAS package as well as reticulate.
rMIDAS relies on Python 3.X to run the MIDAS imputation algorithm (note: Python 3.9 is not yet supported). For most users, the default settings in rMIDAS will be sufficient. Both
complete() check if Python has been initialized and, if not, run the required setup using the best Python 3 version available on your system (as determined by reticulate). The first time you run rMIDAS after installation, you may be prompted to install additional Python dependencies.
If a suitable Python version is not found on your system, you will be asked to manually set the path to a Python binary. You can do this using the next option.
If the automatic setup returns an error or you wish to use a specific Python binary on your system, you can use the
set_python_env() function in rMIDAS, providing an exact path to your chosen Python binary:
set_python_env() you can also set a virtualenv or condaenv environment:
rMIDAS will handle the rest of the initialization and setup.
Note: reticulate only allows you to set a Python binary once per R session, so if you wish to switch to a different Python binary, or have already run
convert(), you will need to restart R prior to using
If you desire more granular control of the R-Python interface, it is possible to use reticulate’s in-built Python configuration tools. Since these commands are outside of rMIDAS, you must also manually call
midas_setup() after configuring your Python install, e.g.:
As with option 2, reticulate only allows you to set a Python binary once per R session. If you wish to switch to a different Python binary, or have already run
convert(), you will need to restart R prior to changing Python version and then call
Sometimes the above three options may fail due to system configuration issues. Here we note a few common issues and fixes.
If you are using a Mac, reticulate may be defaulting to Python 2.7 which is not supported by rMIDAS. If this is the case you will have to configure the R session to use a Python 3 binary, as in option 2 above, by running:
If this returns an error, it’s likely reticulate cannot find a Python environment related to the binary. In which case we recommend restarting the R session and creating a
virtualenv that points to your desired Python 3 binary, as follows: