Skip to content

tidy-finance/environment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tidy Finance Environment

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.

  1. Install Git, R, and RStudio
  2. Download or clone the Tidy Finance Environment repository
  3. Open environment.Rproj in the environment folder that you just downloaded (your R session will then automatically install the R package renv, if not run install.packages("renv"))
  4. Install the R package reticulate (an interface to Python): install.packages("reticulate")
  5. Install Python via reticulate: reticulate::install_python(version="3.10.11", force = TRUE)
  6. Tell renv to use Python: renv::use_python("PATH")
    1. "PATH" on Mac: "~/.pyenv/versions/3.10.11/bin/python"
    2. "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
  7. 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.

Set Environment Variables

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 via reticulate

Do not forget to add these two files to your .gitignore file if you plan to share your work publicly!

Test code

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])

Open Issues

  • Add instructions for VS Code
  • ...

About

A development environment to run the code from tidy-finance.org

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages