1

I'm running something like this: (sorry it is not 100% reproducible, unless you have postgres running in your machine, with mydb and tables created, and the given user and password)

library(RPostgreSQL)
library(tidyverse)
library(dbplyr)

pg_conn <- RPostgreSQL::dbConnect(
    drv = "PostgreSQL", dbname = "mydb", 
    user = "postgres", password = "postgres"
)

table1_pg <- dplyr::tbl(pg_conn, "table1")
table2_pg <- dplyr::tbl(pg_conn, "table2")

table_join <- table1_pg %>%
    left_join(table2_pg, by = c("x" = "x"))

And I get the following error:

Error in nlevels(object) : argument "object" is missing, with no default

And I have no clue what is going on (I am 100% sure the tables exists and each of them has the x column; I can query them, both using the tbl or directly sending an sql with RPostgreSQL::dbGetQuery).

I've googled the problem and searched GitHub and SO, but I found no solution, nor anybody reporting the problem. The closest thing I found is this issue that left_join duplicates join variables. I tried @hadley's dx example there using SQLite, but that works all right on my machine, so perhaps this is a postgres-specific issue?

Here's my sessionInfo()

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] dbplyr_1.0.0      dplyr_0.7.1       purrr_0.2.2.2     readr_1.1.1       tidyr_0.6.3       tibble_1.3.3     
 [7] ggplot2_2.2.1     tidyverse_1.1.1   RPostgreSQL_0.4-1 DBI_0.6-1        

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.11     cellranger_1.1.0 compiler_3.4.0   plyr_1.8.4       bindr_0.1        forcats_0.2.0    tools_3.4.0     
 [8] lubridate_1.6.0  jsonlite_1.5     nlme_3.1-131     gtable_0.2.0     lattice_0.20-35  pkgconfig_2.0.1  rlang_0.1.1     
[15] psych_1.7.5      parallel_3.4.0   haven_1.0.0      bindrcpp_0.2     xml2_1.1.1       httr_1.2.1       stringr_1.2.0   
[22] hms_0.3          grid_3.4.0       glue_1.1.1       R6_2.2.1         readxl_1.0.0     foreign_0.8-68   modelr_0.1.0    
[29] reshape2_1.4.2   magrittr_1.5     scales_0.4.1     rvest_0.3.2      assertthat_0.2.0 mnormt_1.5-5     colorspace_1.3-2
[36] stringi_1.1.5    lazyeval_0.2.0   munsell_0.4.3    broom_0.4.2     
moodymudskipper
  • 46,417
  • 11
  • 121
  • 167
elikesprogramming
  • 2,506
  • 2
  • 19
  • 37
  • Inner join is working? – Tomas Greif Jul 04 '17 at 00:13
  • let me check, ..., mmm nope, `inner_join` throws the same error ("Error in nlevels(object) : argument "object" is missing, with no default") – elikesprogramming Jul 05 '17 at 10:10
  • I've just tested it on a postgres DB and everything works ok for me. Maybe you could try to update your packages? They seem quite old. – Scarabee Jul 20 '17 at 14:04
  • thanks @Scarabee I'll check it out during the weekend. Which packages are old?, ..., I'm not sure, but I think I had almost the latests versions of most packages (dplyr 0.7.1 and dbplyr 1.0.0 which were the latests available at the time, ..., not sure aboutRPostgresSQL though) – elikesprogramming Jul 20 '17 at 21:30
  • Judging by the dates displayed on https://cran.r-project.org/web/packages/RPostgreSQL/NEWS, it seems your `RPostgreSQL` version is from 2013. (also note that you don't have the latest version of `DBI`, which is a dependency of both `dbplyr` and `RPostgreSQL`) – Scarabee Jul 21 '17 at 08:04

0 Answers0