Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spellcheck and ignore vscode files #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ rsconnect/
docs/*.html
#readme rendered
*README.html
#VSCode
.vscode/
8 changes: 4 additions & 4 deletions 02-easy_to_read.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Most languages have several available style guides, which define a set of conventions to produce clean and consistently formatted code. Your style guide will define things like:

* How to use indentation and spacing
* Line length
* Line length
* Naming conventions & formats
* Comment & documentation use

Expand All @@ -28,7 +28,7 @@ Please use this style; consistency will make it easier for colleagues to underst
| Python | [PEP-8](https://www.python.org/dev/peps/pep-0008/) |

## Linters & Code Formatters {#linters}
[Linters](https://en.wikipedia.org/wiki/Lint_%28software%29) are tools that you can use to ensure that you are following a given style guide. Code Formatters will take your code, and format it so that it conforms to a stanard.
[Linters](https://en.wikipedia.org/wiki/Lint_%28software%29) are tools that you can use to ensure that you are following a given style guide. Code Formatters will take your code, and format it so that it conforms to a standard.

| Language | DHSC Recommended Linter / Formatter |
|----------|-------------------------------------------------------|
Expand All @@ -42,7 +42,7 @@ a comment and make life easier for other readers. This includes your future self

Find a balance: avoid meaningless names like `obj` or `foo`; but don't put an entire sentence in a variable name.

Generally, variable names should be nouns and function names should be verbs. You
Generally, variable names should be nouns and function names should be verbs. You

Use single-letter variables only where the use or meaning is clear - such as an iterator for a loop,
or where the letter represents a well-known mathematical property (think: $e = mc^2$).
Expand All @@ -52,7 +52,7 @@ If you find yourself attempting to cram data into variable names (e.g. model_201
## Avoid Overlaps {#dont_overlap}
When naming things be wary of overlapping with other meanings. In one context, using $e$ for energy or $i$ for an iterator might be sensible, but in another context might be confused with $e$ for exponent and $i$ for imaginary as in: $e^{iθ} = cos(θ) + i sin(θ)$.

Be conscious of overlapping names with things which are parts of the language, or popular functions.
Be conscious of overlapping names with things which are parts of the language, or popular functions.
For example in Python, you probably want to avoid common abbreviated library names (`np` or `pd`), or in R be careful about overwriting things like `c` which is the name of the function used to make a vector.

## Name Formats {#name_formats}
Expand Down
4 changes: 2 additions & 2 deletions 03-correct_clear_concise.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ You may find that you have produced code which takes some time to run.
If you expect to run it many times, _then_ its time to think about how you could make things faster.
But don't fall into the trap of optimising before you need to. Ask yourself how much time you are going to save, if it’s a couple of mins, but the optimising takes you several days, is it worth it?

For most languages there are [profiling](https://en.wikipedia.org/wiki/Profiling_%28computer_programming%29) tools you can use to understand resource usage when you need to.
For most languages there are [profiling](https://en.wikipedia.org/wiki/Profiling_%28computer_programming%29) tools you can use to understand resource usage when you need to.

## Concise {#ccfc_concise}
Keeping the amount of code you use to achieve a goal at a minimum can often be a good thing.
There is less code to go wrong or debug, less to explain, style and document.
But, remember that concision is less important than correctness, clarity and speed.
Don't make it shorter than it needs to be, and think of the tradeoff with clarity and flexibility.
Don't make it shorter than it needs to be, and think of the trade-off with clarity and flexibility.
8 changes: 4 additions & 4 deletions 07-demonstrably_correct.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
(ref:demonstrablycorrect-intro)

**You Must** - (ref:demonstrablycorrect-must)

**You Should** - (ref:demonstrablycorrect-should)

**You Could** - (ref:demonstrablycorrect-could)

|Related Areas: | [Version Control](#version_control) <br> [Be Reproducible](#reproducible) |
|--------------- |------------------------------------------------------------|

## Quality Assurance Applies to Code {#qa_code_too}
Just because you have written code rather then making a spreadsheet doesnt mean your analysis is correct.
Code is not exempt from Quality Assurance processes.
Just because you have written code rather then making a spreadsheet doesn't mean your analysis is correct.
Code is not exempt from Quality Assurance processes.
As with any other analysis you need to record evidence that your code is:

* doing the right thing
Expand Down
6 changes: 3 additions & 3 deletions 08-sensible_defaults.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
## General Defaults {#general_defaults}
* Use 'Tidy' data. See the [tidy data principle](#data_structure)!
* Use [git](#git) for version control of code (rather than SVN, Mercurial etc). See the [version control principle](#version_control)
* Use preexisting packages and code before writing your own.
* Use pre-existing packages and code before writing your own.
* Use popular, mature and well supported packages in preference to up & coming ones.

## Language Specific Defaults:
In addition to the general principles, please see the language specifc pages:
In addition to the general principles, please see the language specific pages:

* [Python at DHSC](#py_at_dhsc)
* [R at DHSC](#r_at_dhsc)
* [R at DHSC](#r_at_dhsc)
2 changes: 1 addition & 1 deletion 10-data_structure.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Use tidy data structures as part of your work. You should attempt to convert inc
Any data that is output that may be used in other projects should be in tidy format as well as any other required formats.

## Data Types and Structures {#data_types}
Data *types* are the basic units which your language uses to store data, things like integers, doubles, strings and logical data. Typically you are working with data frames, arrays, matricies or lists. These hold multiple items of data in a data *structure*.
Data *types* are the basic units which your language uses to store data, things like integers, doubles, strings and logical data. Typically you are working with data frames, arrays, matrices or lists. These hold multiple items of data in a data *structure*.

Different types and structures are used for different things, and have different capabilities. To be effective, know about the data types and structures available to you and use the right ones for the job!

Expand Down
44 changes: 22 additions & 22 deletions R/fix_projects.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Creates Rprofile and Renvironment files which fix projects on DHSC Rstudio install

# RStudio startup
# RStudio startup
# https://rviews.rstudio.com/2017/04/19/r-for-enterprise-understanding-r-s-startup/

# N.B. To get a list of all the environment variables which have been set you can run:
Expand All @@ -14,18 +14,18 @@
# 2) set environment variables using R_HOME/etc/Reviron

# __Environment Variables ----
# 3) set _site_ variables using file pointed to by R_ENVIRON,
# 3) set _site_ variables using file pointed to by R_ENVIRON,
# or R_HOME/etc/Reviron.site

# 4) set _user_ variables using e pointed to by R_ENVIRON_USER
# 4) set _user_ variables using e pointed to by R_ENVIRON_USER
# or .Renviron in current dir
# or .Renviron in RHOME

# __RProfile----
# 5) set site profile using file pointed to by R_PROFILE,
# 5) set site profile using file pointed to by R_PROFILE,
# or R_HOME/etc/Rprofile.site

# 6) set site profile using file pointed to by R_PROFILE_USER,
# 6) set site profile using file pointed to by R_PROFILE_USER,
# or R_HOME/etc/Rprofile.site


Expand All @@ -49,45 +49,45 @@
# variable. That is, we can use a .Renviron read at stage 4), to change which
# .Rprofile is read at stage 6).

# Adding an Rprofile to RUser if it doesnt exist ---------------------------
# Adding an Rprofile to RUser if it doesn't exist ---------------------------

# check to see if .RProfile file exists and if not create
profile_path <- file.path(Sys.getenv("R_USER"), ".RProfile")

if (!file.exists(profile_path)) {
profile_text <- '
# Things you might want to change

# options(papersize="a4")
# options(editor="notepad")
# options(pager="internal")

# set the default help type
# options(help_type="text")
options(help_type="html")

# set a site library
# .Library.site <- file.path(chartr("\\", "/", R.home()), "site-library")

# set a CRAN mirror
# local({r <- getOption("repos")
# r["CRAN"] <- "http://my.local.cran"
# options(repos=r)})

# Give a fortune cookie, but only to interactive sessions
# (This would need the fortunes package to be installed.)
# if (interactive())
# if (interactive())
# fortunes::fortune()
'
cat(profile_text, file = profile_path)

print('New Rprofile Written')

} else {

cat(paste0('\nRprofile already present at: \n', profile_path, '\nNo change made\n'),
file = '')

}


Expand All @@ -98,14 +98,14 @@ env_path <- file.path(Sys.getenv("R_USER"), ".Renviron")

if (!file.exists(env_path)) {
env_text <- 'R_PROFILE="${R_USER}/.RProfile"'

cat(env_text, file = env_path)

print('New Renviron Written')

} else {

cat(paste0('\nRenviron already present at: \n',env_path,'\nNo change made'),
file = '')
}

}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# DHSC Coding Principles

See the principles *[HERE](https://datas-dhsc.github.io/coding_principles_book/)*.

## What is this?

This repository contains a set of R markdown documents which, when rendered produce a bookdown site.

The site contains a set of 10 principles, targeted at the DHSC analytical community, with the aim of raising coding standards across the department. These are based on the [MOJ prinicples](https://github.com/moj-analytical-services/our-coding-standards).
The site contains a set of 10 principles, targeted at the DHSC analytical community, with the aim of raising coding standards across the department. These are based on the [MOJ principles](https://github.com/moj-analytical-services/our-coding-standards).

## Publishing Process

The code contains [build](_build.sh) and [deploy](_deploy.sh) scripts which are run by [travis](https://travis-ci.org/mattm-dhsc/coding_principles_book).

These scripts render the book, and push the rendered files to a `gh-pages` branch which is then displayed using [github pages](https://datas-dhsc.github.io/coding_principles_book/).
Expand All @@ -16,4 +19,5 @@ The scripts adapted from the example scripts provided in the [bookdown example](
This process means that the book hosted on github pages is kept in sync with the code which produces it without manual intervention.

## Ownership

The DHSC Coding Principles are maintained by the Data Science Hub, who sit within the Office of the Chief Analyst Directorate.
44 changes: 22 additions & 22 deletions docs/R/fix_projects.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Creates Rprofile and Renvironment files which fix projects on DHSC Rstudio install

# RStudio startup
# RStudio startup
# https://rviews.rstudio.com/2017/04/19/r-for-enterprise-understanding-r-s-startup/

# N.B. To get a list of all the environment variables which have been set you can run:
Expand All @@ -14,18 +14,18 @@
# 2) set environment variables using R_HOME/etc/Reviron

# __Environment Variables ----
# 3) set _site_ variables using file pointed to by R_ENVIRON,
# 3) set _site_ variables using file pointed to by R_ENVIRON,
# or R_HOME/etc/Reviron.site

# 4) set _user_ variables using e pointed to by R_ENVIRON_USER
# 4) set _user_ variables using e pointed to by R_ENVIRON_USER
# or .Renviron in current dir
# or .Renviron in RHOME

# __RProfile----
# 5) set site profile using file pointed to by R_PROFILE,
# 5) set site profile using file pointed to by R_PROFILE,
# or R_HOME/etc/Rprofile.site

# 6) set site profile using file pointed to by R_PROFILE_USER,
# 6) set site profile using file pointed to by R_PROFILE_USER,
# or R_HOME/etc/Rprofile.site


Expand All @@ -49,45 +49,45 @@
# variable. That is, we can use a .Renviron read at stage 4), to change which
# .Rprofile is read at stage 6).

# Adding an Rprofile to RUser if it doesnt exist ---------------------------
# Adding an Rprofile to RUser if it doesn't exist ---------------------------

# check to see if .RProfile file exists and if not create
profile_path <- file.path(Sys.getenv("R_USER"), ".RProfile")

if (!file.exists(profile_path)) {
profile_text <- '
# Things you might want to change

# options(papersize="a4")
# options(editor="notepad")
# options(pager="internal")

# set the default help type
# options(help_type="text")
options(help_type="html")

# set a site library
# .Library.site <- file.path(chartr("\\", "/", R.home()), "site-library")

# set a CRAN mirror
# local({r <- getOption("repos")
# r["CRAN"] <- "http://my.local.cran"
# options(repos=r)})

# Give a fortune cookie, but only to interactive sessions
# (This would need the fortunes package to be installed.)
# if (interactive())
# if (interactive())
# fortunes::fortune()
'
cat(profile_text, file = profile_path)

print('New Rprofile Written')

} else {

cat(paste0('\nRprofile already present at: \n', profile_path, '\nNo change made\n'),
file = '')

}


Expand All @@ -98,14 +98,14 @@ env_path <- file.path(Sys.getenv("R_USER"), ".Renviron")

if (!file.exists(env_path)) {
env_text <- 'R_PROFILE="${R_USER}/.RProfile"'

cat(env_text, file = env_path)

print('New Renviron Written')

} else {

cat(paste0('\nRenviron already present at: \n',env_path,'\nNo change made'),
file = '')
}

}
Loading