#' Factorial
#'
#' Takes the factorial of a number.
#'
#' @param x a number.
#' @param gamma logical. See details.
#'
#' @details gamma = TRUE designates the factorial function as gamma(x + 1),
#' where as if FALSE, x! is used. If FALSE, x must be an integer.
#'
#' @export
#'
#' @examples
#' Fac(4.2)
#' Fac(4, gamma = FALSE)
Fac <- function(x, gamma = TRUE){
if (gamma){
return(gamma(x + 1))
} else {
if (x %% 1 != 0){
message("If gamma = TRUE, x must be a positive integer. NA returned.")
return(NA)
}
if (x < 0){
message("If gamma = TRUE, x must be a positive integer. NA returned.")
return(NA)
} else if (x == 0 | x == 1){
return(1)
} else {
temp <- x - 1
while (temp > 1){
x <- x * temp
temp <- temp - 1
}
return(x)
}
}
}
#' X
#'
#' Returns the input.
#'
#' @param x a miscallaneous object
#'
#' @return The miscallaneous object x.
#' @export
#'
#' @examples
#' X(1)
X <- function(x){
x
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.