The package development follows Hadley Whickham's book R packages, we follow his advise for structuring the package, coding style and testing.
Regarding Git/Github workflow we follow SEDESOL's Git Style Guide.
Follow Hadley's style as in Code style.
Check the style before sending pull request with lintr
:
install.packages("lintr")
lintr::lint_package()
To avoid SQL injection attacks, when queries depend on user input avoid using
paste0
to create SQL commands (dbGetQuery()
), instead consider:
- Use a parameterised query with dbSendQuery() and dbBind():
- When using PostgreSQL placeholders syntax uses
$
and a number indicating the parameter(s)$1, $2, ...
.
-
Use the sqlInterpolate() function to safely combine a SQL string with data
-
Manually escape the inputs using dbQuoteString()
It's important to note that not every variable can be passed with placeholders, such as schemas and tables
One shall use option 1 whenever possible, then option 2 and finally option 3, for they are ordered by level of safety.
Further explanation can be found in the Run Queries Safely section of RStudio Databases using R site.
We use branches, certain branches can NOT be merged or pushed to without pull request:
- master
- develop
- production
Other branches are named according to the following format:
<group_token>/<lead_token>/<tracker-number>
-
group_token: Where group tokens can be: bug, test, feature, junk, doc
-
lead_token: personal tag, selected according to the task to develop, e.g, fruit_prices, sagarpa, etl,... lead_token can be anything except master, develop, release or hotfix.
-
tracker-number: Jira, issue #, Trello task #
Shoud allow you can remember (and understand) what was done in future references.
First line should be used as an email title, when possible shorter than 50 characters. The following lines will further explain the changes. If more information is needed, use bullet points. Language should be imperative, e.g. Fix this bug.
NEVER use git add
(all)
Before doing pull request, check that the branch is correct, usually develop. Keep pull request short.
Title: - - Short Description
Body: What does the pull request do? What should be checked? Give context to the changes. What should be tested?
Indicate:
- Erase branch
- Squash commits
When creating a function we should be careful with SQL injection attacks,
to avoid them, when queries depend on user input avoid using
paste0
to create SQL commands (dbGetQuery()
), instead consider:
- Use a parameterised query with dbSendQuery() and dbBind():
- When using PostgreSQL placeholders syntax uses
$
and a number indicating the parameter(s)$1, $2, ...
.
-
Use the sqlInterpolate() function to safely combine a SQL string with data
-
Manually escape the inputs using dbQuoteString()
One shall use option 1 whenever possible, then option 2 and finally option 3, for they are ordered by level of safety.
Further explanation can be found in the Run Queries Safely section of RStudio Databases using R site