R/print.R

Defines functions print1.linreg

Documented in print1.linreg

#Call the method under the class "linreg" and assign a dynamic function there.
#https://stackoverflow.com/questions/1567718/getting-a-function-name-as-a-string
print1.linreg <- function(formula,  data) {
  #' Method print1.linreg
  #'
  #' @export print1.linreg
  #' @param lan_formula_name User input of the formula
  #' @param lan_data_name User input of the data
  #' @param modelled The full output of the linear regression analysis.
  #'
  #' @return Prints the coefficients of the linear regression analysis of the input data
  #' @examples
  #' print1.linreg(Petal.Length~Species, data = iris)
  #' print1.linreg(Employed ~ ., longley)
  #' @source \url{http://web.nchu.edu.tw/~numerical/course1012/ra/Applied_Regression_Analysis_A_Research_Tool.pdf}

  #Get the user input
  lan_formula_name <- as.character(substitute(formula))
  lan_data_name <- as.character(substitute(data))
  #print(lan_formula_name)

  #But this conversion to characters changes the order of tilda. Thus, I change the order back as follows:
  lan_formula_name = paste(lan_formula_name[2], lan_formula_name[1], lan_formula_name[c(-1,-2)], sep=" ", collapse = "")

  #Print the desired things
  cat("Call:\n")
  str_call1 <- paste("print.linreg(formula = ", lan_formula_name, ", data = ", lan_data_name, ")" , sep="", collapse = " ")
  cat(str_call1, "\n")
  cat("Coefficients:\n")
  #print(paste("print.linreg(formula = ", lan_formula_name, ", data = ", lan_data_name, ")" , sep="", collapse = " "))

  modelled <- linreg(formula, data)
  # #call_coeff <- l_full_linreg$Coeff
  print(modelled$Coeff)
  #return(linreg_model)
}
print1.linreg(Petal.Length~Sepal.Width+Sepal.Length, data=iris)
AdelaidaK/Lab4AdvancedR documentation built on Dec. 17, 2021, 7:40 a.m.