Skip to content

Instantly share code, notes, and snippets.

@iracooke
Last active October 4, 2016 03:36
Show Gist options
  • Save iracooke/8eea2a599e463ded1986adf878855cc6 to your computer and use it in GitHub Desktop.
Save iracooke/8eea2a599e463ded1986adf878855cc6 to your computer and use it in GitHub Desktop.

JCU Townsville Software Carpentry Workshop

To get you and your computer ready, follow instructions under Setup at https://jcu-eresearch.github.io/2016-09-27-SoftwareCarpentry-tsv/

There are three sections we covered: the Unix Shell (using Bash), R (basic, graphs, and loops), and Git/GitHub.

Unix Shell (Bash)

Lesson: https://swcarpentry.github.io/shell-novice/

Data file download link: https://swcarpentry.github.io/shell-novice/data/shell-novice-data.zip

Need to copy and paste with Git Bash? Tips here: https://www.udacity.com/wiki/ud775/git-bash-copy-paste

Note: If you have Git Bash configured to use the Windows console (cmd.exe), you can right-click on the console title bar and select Edit -> Paste.

R

Lesson:  https://swcarpentry.github.io/r-novice-gapminder/

Data file download links: https://raw.githubusercontent.com/resbaz/r-novice-gapminder-files/master/data/gapminder-FiveYearData.csv https://github.com/resbaz/r-novice-gapminder-files/archive/master.zip

R useful links: ggplot2    https://www.rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf Are you courious about the gapminder dataset? https://www.gapminder.org R colour names http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf

Instead of doing the first part of the lesson, in RStudio make a new R script called functions.r and paste the below into it:

Functions for R lesson

f_to_k <- function(temp) {
  kelvin = ((temp - 32) * (5 / 9)) + 273.15
  return(kelvin)
}

f_to_x <- function(temp,unit) {
  if(unit=='K'){kelvin = ((temp - 32) * (5 / 9)) + 273.15
  return(kelvin)} else if(unit=='C'){
    celcius = ((temp - 32) * (5 / 9))
  return(celcius)}else{print('Unit Not Recognised')}
}

calcGDP <- function(dat) {
  gdp = dat$pop * dat$gdpPercap
  return(gdp)
}

calcGDP2 <- function(dat, year=NULL, country=NULL) {
  if(!is.null(year)) {
    dat = dat[dat$year %in% year, ]
  }
  if (!is.null(country)) {
    dat = dat[dat$country %in% country,]
  }
  gdp = dat$pop * dat$gdpPercap
  
  new = cbind(dat, gdp=gdp)
  return(new)
}

Git

Lesson: https://swcarpentry.github.io/git-novice/

Vim cheat-sheet: http://vim.rtorr.com/     

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment