#' Square a numeric vector.
#'
#' This function takes in a atomic numeric vector that contains more than 3 elements, squares each element, and sum them up
#' @param a A numeric vector that contains more than 3 elements
#' @param b A logical vector True / False to decide if print the sum
#' @return Squared numeric vector
#' @export
MyFunction <- function(a, b) {
if (length(a) < 3) {
warning('Please enter a vector that contains more than 3 elements!')
}
else {
sum <- 0
for (i in 1:length(a)) {
a[i] <- a[i]^2
sum <- sum + a[i]
}
if (b == TRUE) {
cat('The sum of all elements in the vector a is: ', sum)
}
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.