-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
64 lines (42 loc) · 2.62 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
---
output: github_document
---
# redbulltools
The redbulltools package provides helper and utility functions for Data Science teams at Red Bull. Most of these are simply wrappers around existing utilities and functions that should serve to improve speed, reproducibility and consistency.
## Setting up
To get everything working properly you will need to use the `config` package and your environment variables to store all sensitive credentials or connection information to your R environment.
Templates for the `config.yml` file and `.Renviron` file are available in the templates folder of this package.
## Functionality
### Connecting to internal databases
The `connect_to_database` function is a wrapper around `DBI::dbConnect` that allows you to reference connection parameters that are saved in your configuration variables.
To use this function, firstly make sure you have your database connection parameters stored in your `.Renviron` file and that your `config.yml` file is set up as in the template (in this repository):
```{r eval = F}
my_new_database:
driver: !expr Sys.getenv("NEW_DB_DRIVER")
uid: !expr Sys.getenv("NEW_DB_UID")
pwd: !expr Sys.getenv("NEW_DB_PWD")
server: !expr Sys.getenv("NEW_DB_SERVER")
port: !expr Sys.getenv("NEW_DB_PORT")
```
Note that the config variable is the name of the database ("my_new_database") and the sub-variables are all lower-case.
To connect to this database you can simply reference it by name.
```{r eval = F}
new_db_connection <- connect_to_database("my_new_database")
```
This function can also pass additional variables to dbConnect.
```{r eval = F}
# If we want to connect to a specific DB within the my_new_database environment (e.g. SQL)
new_db_connection_2 <- connect_to_database("my_new_database", DB = "THISDB")
```
### Connecting to the Bulldrive
Assuming you have your Bulldrive credentials stored correctly using config and environment variables you can quickly save your token to your local options using the following syntax.
You need to have [egnyter](http://github.com/deathbydata/egnyter) installed for this function to work.
```{r eval=F}
connect_to_bulldrive()
get_parameter("token")
```
### Creating a new project folder structure
When starting a new project you can use the `create_project_folder` function to set up a [Cookiecutter](https://drivendata.github.io/cookiecutter-data-science/) style directory structure in the Bulldrive. You need to have [egnyter](http://github.com/deathbydata/egnyter) installed and the `BULLDRIVE_PROJECT_FOLDER` environment variable set for this function to work.
```{r eval=F}
create_project_folders("My Super Cool Project")
```