Please consider creating an issue in this repository if you run into any problems, so that other people can also look them up in the future.
This repository helps you to set up a development environment where you can work with both R and Python using the RStudio IDE.
- Install Git, R, and RStudio
- Download or clone the Tidy Finance Environment repository
- Open
environment.Rproj
in the environment folder that you just downloaded (your R session will then automatically install the R packagerenv
, if not runinstall.packages("renv")
) - Install the R package
reticulate
(an interface to Python):install.packages("reticulate")
- Install Python via
reticulate
:reticulate::install_python(version="3.10.11", force = TRUE)
- Tell
renv
to use Python:renv::use_python("PATH")
"PATH"
on Mac:"~/.pyenv/versions/3.10.11/bin/python"
"PATH"
on Windows:"C:/Users/<User>/AppData/Local/r-reticulate/r-reticulate/pyenv/pyenv-win/versions/3.10.11/python.exe"
where<User>
is your user name
- Tell
renv
to install all required packages:renv::restore()
We decided to use Python version 3.10.11, after many trial and errors to set-up the environment that we used to write Tidy Finance with Python and maintain Tidy Finance with R on both Windows and Mac.
We use environment variables to secretly store our WRDS login credentials.
.Renviron
is used by RStudio for all R code.env
is used by Rstudio when it runs Python code viareticulate
Do not forget to add these two files to your .gitignore
file if you plan to share your work publicly!
Run this in the R console of your RStudio to check whether R code works:
library(tidyverse)
mtcars |>
filter()
Run this in the R console of your RStudio to check whether R code works:
library(tidyverse)
mtcars |>
filter(mpg > 20)
Run this in the R console of your RStudio to check whether Python code works:
reticulate::repl_python()
import numpy as np
import pandas as pd
pd.Series([1, 3, 5, np.nan, 6, 8])
- Add instructions for VS Code
- ...