Permalink
Browse files

function to quickly create a formula object

  • Loading branch information...
1 parent ded2fbf commit 8aff17c7f1bede29b15e31b063984c1183272019 erik 'quantitative warlock' shilts committed Feb 4, 2012
Showing with 11 additions and 0 deletions.
  1. +11 −0 R/create_formula.R
View
@@ -0,0 +1,11 @@
+#' Creates Formula Object From Strings
+#' Simplifies creation of a formula object given strings of variables names.
+#'
+#' @param lhs name of left hand side (dependent) variable; must be a singleton
+#' @param rhs name(s) of right hand side (independent) variables
+#' @author Erik Shilts
+#' @export
+create_formula <- function(lhs, rhs) {
+ stopifnot(unique(lhs) == 1)
+ as.formula(sprintf('%s ~ %s', unique(lhs), paste(unique(rhs), collapse = '+')))
+}

0 comments on commit 8aff17c

Please sign in to comment.