CSB Assignment Week 2

From "A B C"
Jump to navigation Jump to search

Assignments for Week 2
Collaboration tools, initializing our project.

< Assignment 1 Assignment 3 >

Note! This assignment is currently active. All significant changes will be announced on the mailing list.

 
 

Assigned material - concepts, exercises and reading - will be reflected in next week's evaluation and feedback session. Please remember to contribute to self-evaluation questions by Tuesday at noon.


 


 

Warm up

You go to the Toronto Zoo. You see giraffes, ostriches and a green tree python. Altogether they have 30 eyes and 44 legs.

How many necks does this group of animals have? [I don't know...]

Seriously?
This may be easier than you think.
Maybe you are wondering whether snakes have necks? (TLDR; It's complicated. But: yes.)
Or do you need a hint? [Ok. A hint please...]

Maybe you are just confused by some irrelevant information.[No. I still don't get it...]

It's really quite simple. Thirty eyes are in fifteen heads. Fifteen heads are attached to fifteen necks. Fifteeeen. No more. No less.
How many of each? You could calculate this by substitution. Eight giraffes. Six ostriches. And one snake. But that wasn't the question.


Software Development

Task:
Great ideas will come to nothing if we can't put them into code.

  • For an introduction to concepts of developing software, carefully read the Software Development page on this Wiki.
  • Work through the knitr and RMarkdown tutorial.
  • Get a github account if you don't have one yet.


 

Advancing your R skills

 


Task:

In this task you set up a github repository for an R project. You create the project on your local machine, write some code and customize it. Then you upload your local project to your github repository.


  • Navigate to your github account (create an account if you don't have one yet.)
  • Click on New Repository on your profile page in the "Your repositories" section
  • Give the repository a useful, stable name for a project - "sample_project" or "test_project" would be appropriate for this task.
  • Check Initialize this repository with a README
    • ... and click Create repository.


 
  • Open RStudio
  • Click on File → New Project ...
  • Select Version Control
  • Select Git
  • Paste the Repository URL of your Github project ...
  • Use the github repository name as your Project directory name and Browse... to select a good folder where the project folder can live on your computer.
  • Click Create Project.
  • Click File → New File → R Script
  • Write some code: for example, write a function that returns n random passwords of length l (where n and l are parameters). l is the number of syllables to use. A syllable is defined as a consonant or consonant cluster (onset) and a vowel or diphthong (nucleus).
  • Save the script file in your project directory. Make sure that it has the extension .R (RStudio should have added the extension by default.)
  • Set your working directory: use Session → Set Working Directory → To Project Directory
  • Use rm(list = ls()) to clear your workspace.
  • Open Tools → Project Options... and set the following options:
  • in the General pane:
    • Restore most recetly opened project ... No
    • Restore previously open source documents ... Yes
    • Restore .RData ... No
    • Save workspace ... No
    • Always save history ... No

This will ensure you start the project with a clean slate and the same environment every time. If you do not do this, your project may not be fully reproducible code that can be shared among many people.


  • In the Code editing pane:
    • Check all options ON
    • Set Tab width to 3 spaces
    • Make sure Text-encoding is UTF-8

All other options are probably oK in their default state - packrat should be OFF (but you may turn it ON if you need it at some point and you understand what it does.)


  • Click OK.
  • Now open a new text file (not R script), add a single blank line and save this in your project directory under the name .Rprofile. R uses this file to customize a working session. Right now there is nothing in the file but you can always put something into the file later.
  • Close the .RProfile pane, only your R script should be open. This window will be restored when you open your project and you don't want .Rprofile to be opened every time you start the project.
  • Quit RStudio.


  • Open the project folder and delete the .Rhistory file (there is probably one there from when the project was originally created.)
  • Now restart R Studio and click File → Open Project in a New Window.... Everything should be there:
    • Your workspace should be empty
    • Your working directory should be the project folder. Test this with getwd()
    • Your source file should be open to use and develop further.

One thing left to do: you haven't synchronized your project on Github yet.

  • Open the version control interface with Tools → Version Control & Commit ...
  • Click on each files' check-box to "stage" it, in turn, write a meaningful commit message, and click on Commit. Close the log windows.
  • Finally: click on Push to upload all changes to your github repository.
  • In your browser, navigate back to your github repository and verify that all changes have arrived.


Your project setup is now complete. To review the ideas we covered here, look up the following two R Studio support pages:


 


 
That is all.


 

Footnotes and references

 



 


 
Ask, if things don't work for you!
If anything about the assignment is not clear to you, please ask on the mailing list. You can be certain that others will have had similar problems. Success comes from joining the conversation.
... are required reading.


 



< Assignment 1 Assignment 3 >