R Introduction
Introductory course to R and Data analysis
Main file is scripts/markdown/introduction.pdf
How to keep your code clean
Coding convention
-
Pick a naming convention and stick to it
- snake_case = "this is a nice too"
- camelCase = "this is ok too"
-
Comment your code
-
Look at the google style book to make sure your code is easilly readable by anyone
- Google style guide
- they advice to use only "<-" and not "=" but I personally think it is pointless
Storage
Keep a README.md file at the root of your folder explaining where everything is, helping someone that knows nothing about your data to navigate your work. Keeping your work in the cloud, through services like dropbox, icloud, or google drive. The best would be github but it is not easy in the beginning.
Folders
Keep your folder clean, with clear names in minuscules separated by "_" :
-
data
- raw
- preprocessed
- analysis
- analysis_one ...
-
scripts
- preprocessing: scripts that transforms the raw data in processed data
- analysis: scripts that use preprocessed data and performs analysis on it
- markdown: your markdown files
- r_files: other R files, like utility functions
-
media: here should go any ressources, presentations, images you produced or needed etc...
- presentations
- graphics
- text
- notes
-
backups: you might need a backup folder when in doubt
- data
- script
- media
Cheat sheet
Install R
Get RStudio
- Here +++
SWIRL
For a good interactive tutorial directly built in R try SWIRL
To start a swirl session enter in the console : +++
install.packages("swirl")
library("swirl")
swirl()
Style Guides - Good to read before programming
Books
Data Exploration
Ressources
- The Tidyverse
- Psych package Guide for the impatient ++
- https://www.youtube.com/watch?v=40tyOFMZUSM
- https://www.youtube.com/watch?v=mAOvzjqQcO0
Import
Tidy
Transformation
Visualization
Statistics
- Ben Meuleman Bayes Factor presentation
- Structural Equation Modeling
- packages
- pastecs: stat.desc
- fBasics: basicStats
Modeling
Videos
Packages
- Zelig
- Caret
Interpolation and Fitting
- https://stat.ethz.ch/R-manual/R-patched/library/stats/html/approxfun.html
- https://stat.ethz.ch/R-manual/R-devel/library/stats/html/splinefun.html
- https://stat.ethz.ch/R-manual/R-devel/library/stats/html/predict.smooth.spline.html
Diffusion model
Markdown
Intro
- http://rmarkdown.rstudio.com/
- Two main library for formatting
Examples
R packages
Creating it
- Video
- http://r-pkgs.had.co.nz/vignettes.html
- Video
- https://cran.r-project.org/doc/manuals/r-release/R-exts.html
Documentation/Comments
- http://r-pkgs.had.co.nz/man.html
- http://kbroman.org/pkg_primer/pages/docs.html
- http://stackoverflow.com/questions/12038160/how-to-not-run-an-example-using-roxygen2
- For example code you do not want to run use :
\dontrun{}
- For example code you do not want to run use :
Import/Depend
- http://blog.obeautifulcode.com/R/How-R-Searches-And-Finds-Stuff/
- http://kbroman.org/pkg_primer/pages/build.html
Putting it on github
Putting it on cran
Install a package from source file
Object Oriented programming
- https://stat.ethz.ch/R-manual/R-devel/library/methods/html/refClass.html
- https://cran.r-project.org/web/packages/R6/vignettes/Introduction.html
Choosing between object type
- http://stackoverflow.com/questions/27219132/creating-classes-in-r-s3-s4-r5-rc-or-r6
- http://stackoverflow.com/questions/11653127/what-does-the-function-invisible-do
Multicore
Debugging
- https://cran.r-project.org/doc/manuals/r-patched/R-exts.html#Debugging-R-code
- options(error = dump.frames); debugger()
- stringAsFactor options causes frequent error
Work in progress - help welcome !
Bavelier Lab 2016
(MIT License)