Skip to content
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

bind_rows: Expecting a string vector: [type=NULL; required=STRSXP]. #3349

Closed
MatthieuStigler opened this issue Feb 9, 2018 · 5 comments
Closed
Assignees
Labels

Comments

@MatthieuStigler
Copy link

@MatthieuStigler MatthieuStigler commented Feb 9, 2018

I am being stuck with dplyr 0.7.4 trying to use bind_rows() (initially: unnest()) on a list of data-frames obtained with broom::augment(), I get error message:
Error in bind_rows_(x, .id) :
Expecting a string vector: [type=NULL; required=STRSXP].

I don't see what is not working, it seems that this is due to a few offending columns... Am I doing something wrong or is there an issue down there?

library(tidyverse)
library(broom)

reg1 <- lm(y~ ., data=freeny)
reg2 <- lm(y~ . -price.index, data=freeny)
regs_df <- data_frame(name=c("reg1", "reg2"),
                      data=list(reg1, reg2)) %>%
  mutate(aug=map(data, augment))

## doesn't work?
regs_df$aug %>%
  bind_rows()

# seem to be linked to specific variables?
vars_issue <- c(2, 9, 12, 13)

regs_df$aug %>%
  map(~select(., -vars_issue)) %>%
  bind_rows()

## what is specific about these variables?
regs_df[1,]$aug[[1]] %>%
  select(vars_issue)

Thanks!!

@batpigandme
Copy link
Member

@batpigandme batpigandme commented Feb 9, 2018

Could you please submit this as a self-contained reprex (short for minimal reproducible example)?

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page.

@mmstigler
Copy link

@mmstigler mmstigler commented Feb 9, 2018

Oh, sorry about that! Here is the reprex version of the code:

library(tidyverse)
#> ── Attaching packages ────────────────────────────────── tidyverse 1.2.1 ──
#> ✔ ggplot2 2.2.1     ✔ purrr   0.2.4
#> ✔ tibble  1.4.2     ✔ dplyr   0.7.4
#> ✔ tidyr   0.7.2     ✔ stringr 1.2.0
#> ✔ readr   1.1.1     ✔ forcats 0.2.0
#> ── Conflicts ───────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag()    masks stats::lag()
library(broom)

reg1 <- lm(y~ ., data=freeny)
reg2 <- lm(y~ . -price.index, data=freeny)
regs_df <- data_frame(name=c("reg1", "reg2"),
                      data=list(reg1, reg2)) %>%
  mutate(aug=map(data, augment))

## doesn't work?
regs_df$aug %>%
  bind_rows()
#> Error in bind_rows_(x, .id): Expecting a string vector: [type=NULL; required=STRSXP].

# seem to be linked to specific variables?
vars_issue <- c(2, 9, 12, 13)

regs_df$aug %>%
  map(~select(., -vars_issue)) %>%
  bind_rows() %>%
  head
#>   .rownames lag.quarterly.revenue price.index income.level
#> 1   1962.25               8.79636     4.70997      5.82110
#> 2    1962.5               8.79236     4.70217      5.82558
#> 3   1962.75               8.79137     4.68944      5.83112
#> 4      1963               8.81486     4.68558      5.84046
#> 5   1963.25               8.81301     4.64019      5.85036
#> 6    1963.5               8.90751     4.62553      5.86464
#>   market.potential  .fitted     .se.fit      .hat     .sigma
#> 1          12.9699 8.789170 0.007561687 0.2636055 0.01493540
#> 2          12.9733 8.802520 0.006755339 0.2103834 0.01478897
#> 3          12.9774 8.821706 0.007021352 0.2272786 0.01488781
#> 4          12.9806 8.838953 0.006553851 0.1980205 0.01407319
#> 5          12.9831 8.883883 0.009562633 0.4215722 0.01393696
#> 6          12.9854 8.920665 0.006373890 0.1872950 0.01462400

## what is specific about these variables?
regs_df[1,]$aug[[1]] %>%
  select(vars_issue) %>%
  head
#>         y       .resid     .cooksd .std.resid
#> 1 8.79236  0.003189835 0.004560545  0.2523896
#> 2 8.79137 -0.011149901 0.038678336 -0.8519642
#> 3 8.81486 -0.006845771 0.016447669 -0.5287732
#> 4 8.81301 -0.025942587 0.191054486 -1.9669357
#> 5 8.90751  0.023627347 0.648560736  2.1093513
#> 6 8.93673  0.016065357 0.067482031  1.2099918

@romainfrancois romainfrancois self-assigned this Mar 5, 2018
@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Mar 5, 2018

The issue is these columns are flagged as objects:

> data <- regs_df$aug %>%
+   map(~select(., vars_issue))
> 
> data %>% map( ~map_lgl(., is.object) )
[[1]]
         y     .resid    .cooksd .std.resid 
      TRUE       TRUE       TRUE       TRUE 

[[2]]
         y     .resid    .cooksd .std.resid 
      TRUE       TRUE       TRUE       TRUE 

and not the others.

> regs_df$aug %>%
+   map(~select(., -vars_issue)) %>% map( ~map_lgl(., is.object) )
[[1]]
            .rownames lag.quarterly.revenue           price.index          income.level      market.potential               .fitted               .se.fit                  .hat                .sigma 
                FALSE                 FALSE                 FALSE                 FALSE                 FALSE                 FALSE                 FALSE                 FALSE                 FALSE 

[[2]]
            .rownames lag.quarterly.revenue           price.index          income.level      market.potential               .fitted               .se.fit                  .hat                .sigma 
                FALSE                 FALSE                 FALSE                 FALSE                 FALSE                 FALSE                 FALSE                 FALSE                 FALSE

fix on the way.

@MichaelChirico
Copy link

@MichaelChirico MichaelChirico commented Mar 6, 2018

@lock
Copy link

@lock lock bot commented Sep 8, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Sep 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

6 participants