Skip to content
Please note that GitHub no longer supports your web browser.

We recommend upgrading to the latest Google Chrome or Firefox.

Learn more
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle spaces in formula variables #80

Closed
leeper opened this issue Jan 9, 2018 · 2 comments
Closed

Handle spaces in formula variables #80

leeper opened this issue Jan 9, 2018 · 2 comments
Labels
bug

Comments

@leeper
Copy link
Owner

@leeper leeper commented Jan 9, 2018

margins() chokes on formulae on variable names with spaces in formulae:

> mtcars$"No of Cylinders" <- mtcars$cyl
> margins(lm(mpg ~ `No of Cylinders`, data = mtcars))
Error in parse(text = x) : <text>:1:4: unexpected symbol
1: No of
       ^
> traceback()
11: parse(text = x)
10: all.vars(parse(text = x))
9: FUN(X[[i]], ...)
8: lapply(X = X, FUN = FUN, ...)
7: sapply(names(classes), function(x) all.vars(parse(text = x)))
6: find_terms_in_model(model, variables = variables)
5: marginal_effects.lm(model = model, data = data, variables = variables, 
       type = type, eps = eps, ...)
4: marginal_effects(model = model, data = data, variables = variables, 
       type = type, eps = eps, ...)
3: build_margins(model = model, data = data_list[[i]], variables = variables, 
       type = type, vcov = vcov, vce = vce, iterations = iterations, 
       unit_ses = unit_ses, eps = eps, ...)
2: margins.lm(lm(mpg ~ `No of Cylinders`, data = mtcars))
1: margins(lm(mpg ~ `No of Cylinders`, data = mtcars))
@leeper leeper added the bug label Jan 9, 2018
@leeper leeper closed this in 9cffafb Jan 10, 2018
@leeper

This comment has been minimized.

Copy link
Owner Author

@leeper leeper commented Jan 11, 2018

Oops, it's back.

> margins::margins(lm(mpg ~ `No of Cylinders`, data = mtcars))
Error in parse(text = x, keep.source = FALSE) : 
  <text>:1:5: unexpected symbol
1: ~No of
        ^
> traceback()
17: parse(text = x, keep.source = FALSE)
16: eval(parse(text = x, keep.source = FALSE)[[1L]])
15: formula(eval(parse(text = x, keep.source = FALSE)[[1L]]))
14: formula.character(object, env = baseenv())
13: formula(object, env = baseenv())
12: as.formula(new)
11: update.formula(~., paste0("~", x))
10: update(~., paste0("~", x))
9: all.vars(update(~., paste0("~", x)))
8: FUN(X[[i]], ...)
7: lapply(terms, function(x) all.vars(update(~., paste0("~", x))))
6: unlist(lapply(terms, function(x) all.vars(update(~., paste0("~", 
       x)))))
5: unique(unlist(lapply(terms, function(x) all.vars(update(~., paste0("~", 
       x))))))
4: clean_terms(names(classes)[!classes %in% c("factor", "ordered", 
       "logical")])
3: find_terms_in_model(model, variables = variables)
2: margins.lm(lm(mpg ~ `No of Cylinders`, data = mtcars))
1: margins::margins(lm(mpg ~ `No of Cylinders`, data = mtcars))
@leeper leeper reopened this Jan 11, 2018
@leeper

This comment has been minimized.

Copy link
Owner Author

@leeper leeper commented Jan 23, 2018

Fixed (?) again by e140fe9

@leeper leeper closed this Jan 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.