Skip to content

Commit

Permalink
Merge pull request #11 from SussexPsychMethods/patch
Browse files Browse the repository at this point in the history
Update 06_functions_packages.Rmd
  • Loading branch information
ljcolling authored Nov 3, 2020
2 parents bb5205e + 7a3e7c7 commit 05c8c72
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions inst/tutorials/06_functions_packages/06_functions_packages.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,39 @@ install.packages <- function(x){
return(glue::glue("{x} installed..."))
}
plus_5 <- function(a_number){
if(!is(a_number,"numeric")){
stop("The input must be a number! Don't add \" \"")
}
a_number + 5
}
say_hello <- function(a_letter_string){
if(!is(a_letter_string,"character")){
stop("The input must be a letter string! Don't forget the \" \"")
}
cat("Hello", paste0(a_letter_string,"!"))
}
describe_input <- function(input_variable){
input = substitute(input_variable)
if(!is(input,"name")){
stop("input_variable must be a variable")
}
input_type <- dplyr::case_when(
is(input_variable,"numeric") ~ "numbers",
is(input_variable,"character") ~ "letters",
TRUE ~ "something I wanted expecting!"
)
cat(paste0("The input given to input_variable was a variable called: ",input),"\n")
cat(input,"contains:",input_type,"\n")
cat(input,"contains the content:",input_variable)
}
```

## About this tutorial
Expand Down Expand Up @@ -101,38 +134,7 @@ The rules are:
- Variable inputs **don't** have `" "`

```{r}
plus_5 <- function(a_number){
if(!is(a_number,"numeric")){
stop("The input must be a number! Don't add \" \"")
}
a_number + 5
}
say_hello <- function(a_letter_string){
if(!is(a_letter_string,"character")){
stop("The input must be a letter string! Don't forget the \" \"")
}
cat("Hello", paste0(a_letter_string,"!"))
}
describe_input <- function(input_variable){
input = substitute(input_variable)
if(!is(input,"name")){
stop("input_variable must be a variable")
}
input_type <- dplyr::case_when(
is(input_variable,"numeric") ~ "numbers",
is(input_variable,"character") ~ "letters",
TRUE ~ "something I wanted expecting!"
)
cat(paste0("The input given to input_variable was a variable called: ",input),"\n")
cat(input,"contains:",input_type,"\n")
cat(input,"contains the content:",input_variable)
}
```

We can take a look at this in action!
Expand Down

0 comments on commit 05c8c72

Please sign in to comment.