Skip to content

Instantly share code, notes, and snippets.

@ignacioriveros1
Created April 20, 2021 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ignacioriveros1/797bc12b7eb161caba88c43cd7e6fe78 to your computer and use it in GitHub Desktop.
Save ignacioriveros1/797bc12b7eb161caba88c43cd7e6fe78 to your computer and use it in GitHub Desktop.
#--------------------------------------------#
# File: settings.R
# Author: Ignacio Riveros
#--------------------------------------------#
# Remove all
rm(list = ls())
## Packages required
ipak <- function(pkg) {
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
packages = c(
'tidyverse',
'foreign',
'ggplot2',
'RColorBrewer',
'Hmisc',
'plm',
'sandwich',
'lmtest',
'stargazer'
)
ipak(packages)
env = Sys.getenv("LOGNAME")[1]
if (is.null(env) | env == "") {
# On windows machines
env = Sys.getenv("USERNAME")
}
get_user <- function(env) {
if (env == "machine_name1") {
USER = "User 1"
}
else if (env == "machine_name2") {
USER = "User 2"
}
return(USER)
}
USER = get_user(env)
get_path = function(user) {
if (user == "User 1") {
path = "my/path/to/the/code"
gd = "my/path/to/the/data"
}
else if (user == "Ignacio Urria") {
path = "other/path/to/the/code"
gd = "other/path/to/the/data"
}
return(c(path, gd))
}
# Paths
REPO_PATH = get_path(USER)[1]
DATA_PATH = get_path(USER)[2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment