library(dovetail) library(knitr) opts_chunk$set(error = TRUE)
x <- "The cat purrrs on my lap."
#' ## Count words #' #' 1. How many words are in the sentence `x`? #' #' @solution #' #' There is more than one way of doing this but here is a solution. #' #' ```r n_words <- length(strsplit(x, " ")[[1]]) n_words #' ``` #' #' 1. How many letters are in the sentence `x`? #' #' #' ```r n_chars <- nchar(gsub("[^a-zA-Z]", "", x)) n_chars #' ```
Now that we know that there are r n_words
words and r n_chars
characters in the sentence. Let's add these 2 numbers
#' ## add these 2 numbers #' #' @solution #' Are these variables available? #' #' ```r #' n_words + n_chars #' ```
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.