Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

function to quickly create a formula object

  • Loading branch information...
commit 8aff17c7f1bede29b15e31b063984c1183272019 1 parent ded2fbf
erik 'quantitative warlock' shilts authored
Showing with 11 additions and 0 deletions.
  1. +11 −0 R/create_formula.R
View
11 R/create_formula.R
@@ -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 = '+')))
+}
Please sign in to comment.
Something went wrong with that request. Please try again.