Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Organising software components

Software organises sequences of instructions in components that perform a specific task.  For example, some practice in Become familiar with R Studio and basic concepts of R, a basic function was created to prevent coding again the same line of codes. Functions can be grouped together and packaged as some units of code, that can be shared and used again.

...

  1. Download the following file: some-functionsv2.R
  2. Open it in R studio. You should see two functions named sample.large.numbers and sample.negative.numbers
  3. In the help, search for the source function. Read description of the function and the list of arguments. 
  4. Go back to the script and click on the source button.  In the console, a call the source function is made. In the environment,  a list of functions should have appeared. Can you see the two new functions?
  5. Call the the two functions. Try
    1. large.numbers <- sample.large.numbers() 
    2. negative.numbers <- sample.negative.numbers()
    3. large.numbers <- sample.large.numbers(n = 10) 
    4. negative.numbers <- sample.negative.numbers(n= 10, min.number = 100(You should see an error message !)
    5. large.numbers <-sample.large.numbers(max.number = -10(You should see an error message !)

Some of these calls displayed some error messages and some others have returned some values, in a vector. However, the function was found in the Environment and behaved as they were coded. 

...