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

dyadyear atopalliance left_join bug #15

Closed
jandresgannon opened this issue Mar 24, 2023 · 6 comments
Closed

dyadyear atopalliance left_join bug #15

jandresgannon opened this issue Mar 24, 2023 · 6 comments

Comments

@jandresgannon
Copy link

When piping add_atop_alliance() to create_dyadyears, I get the following error:

Error in `left_join()`:
! `by` must be supplied when `x` and `y` have no common variables.
ℹ Use `cross_join()` to perform a cross-join.
Backtrace:
  1. ... %>% add_atop_alliance()
 13. dplyr:::left_join.data.frame(data, .)

The full traceback shows the following:

18: stop(fallback)
17: signal_abort(cnd, .file)
16: abort(message, call = error_call)
15: join_by_common(x_names, y_names, error_call = error_call)
14: join_mutate(x = x, y = y, by = by, type = "left", suffix = suffix, 
        na_matches = na_matches, keep = keep, multiple = multiple, 
        unmatched = unmatched, relationship = relationship, user_env = caller_env())
13: left_join.data.frame(data, .)
12: left_join(data, .)
11: tbl_vars_dispatch(x)
10: structure(vars, groups = group_vars, class = c("dplyr_sel_vars", 
        "character"))
9: new_sel_vars(tbl_vars_dispatch(x), group_vars(x))
8: tbl_vars(tbl)
7: tbl_at_vars(tbl, vars, .include_group_vars = .include_group_vars, 
       error_call = error_call)
6: tbl_at_syms(.tbl, .vars, .include_group_vars = .include_group_vars, 
       error_call = error_call)
5: manip_at(.tbl, .vars, .funs, enquo(.funs), caller_env(), .include_group_vars = TRUE, 
       ..., .caller = "mutate_at")
4: mutate_at(., vars("atop_defense", "atop_offense", "atop_neutral", 
       "atop_nonagg", "atop_consul"), ~ifelse(is.na(.) & year <= 
       2018, 0, .))
3: atop_alliance %>% left_join(data, .) %>% mutate_at(vars("atop_defense", 
       "atop_offense", "atop_neutral", "atop_nonagg", "atop_consul"), 
       ~ifelse(is.na(.) & year <= 2018, 0, .))
2: add_atop_alliance(.)
1: create_dyadyears(system = "cow", subset_years = c(1970:2014), 
       directed = TRUE) %>% add_atop_alliance()

Session info:

R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.10

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] peacesciencer_1.1.0 lubridate_1.9.2     forcats_1.0.0      
 [4] stringr_1.5.0       dplyr_1.1.1         purrr_1.0.1        
 [7] readr_2.1.4         tidyr_1.3.0         tibble_3.2.1       
[10] ggplot2_3.4.1       tidyverse_2.0.0     magrittr_2.0.3     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10       here_1.0.1        lattice_0.20-45  
 [4] rprojroot_2.0.3   digest_0.6.31     utf8_1.2.3       
 [7] R6_2.5.1          cellranger_1.1.0  labelled_2.10.0  
[10] evaluate_0.20     coda_0.19-4       httr_1.4.5       
[13] pillar_1.9.0      rlang_1.1.0       curl_5.0.0       
[16] readxl_1.4.2      rstudioapi_0.14   minqa_1.2.5      
[19] data.table_1.14.8 geosphere_1.5-18  nloptr_2.0.3     
[22] Matrix_1.5-3      rmarkdown_2.20    splines_4.2.1    
[25] lme4_1.1-32       foreign_0.8-82    munsell_0.5.0    
[28] compiler_4.2.1    xfun_0.37         pkgconfig_2.0.3  
[31] htmltools_0.5.4   tidyselect_1.2.0  rio_0.5.29       
[34] fansi_1.0.4       tzdb_0.3.0        withr_2.5.0      
[37] MASS_7.3-58.1     grid_4.2.1        nlme_3.1-159     
[40] arm_1.13-1        gtable_0.3.3      lifecycle_1.0.3  
[43] scales_1.2.1      zip_2.2.2         cli_3.6.1        
[46] stringi_1.7.12    sp_1.6-0          stevemisc_1.6.0  
[49] generics_0.1.3    vctrs_0.6.1       boot_1.3-28      
[52] openxlsx_4.2.5.2  tools_4.2.1       glue_1.6.2       
[55] hms_1.1.3         abind_1.4-5       parallel_4.2.1   
[58] fastmap_1.1.1     timechange_0.2.0  colorspace_2.1-0 
[61] knitr_1.42        haven_2.5.2      

Replicable code for my problem below.

dyads <- create_dyadyears(system = "cow",
                          subset_years = c(1970:2014),
                          directed = TRUE) %>%
  add_atop_alliance() %>%
  add_capital_distance() %>%
  add_contiguity() %>%
  add_cow_majors() %>%
  add_cow_trade() %>%
  add_democracy() %>%
  add_fpsim() %>%
  add_nmc() %>%
  add_strategic_rivalries()

Note that if I comment out add_atop_alliance(), it runs perfectly fine. If I move add_atop_alliance() to somewhere else in the pipe, it breaks. I listwise went through every part of the pipe and no other one causes problems

@svmiller
Copy link
Owner

I'm actually not able to reproduce this with the MWE you provided, which would be a first because this otherwise seems like an error that might have happened with me being clumsy with something.

The operative data frame by which something would seem to happen would be atop_alliance, but I can't see anything yet that would seem to be triggering this. In this example, if you enter atop_alliance into the session, do you see something without ccode1, ccode2, and year?

@jandresgannon
Copy link
Author

Interesting! You're right. When I enter atop_alliance it seems it loads the alliance level version of ATOP dataset (atop5_0a.csv) rather than the member level (atop5_0m.csv)

My suspicion is based on the output of colnames(atop_alliance) being:

[1] "atopid"      "atopidphase" "begyr"       "endyr"       "phase"       "bilat"       "defense"     "terrres"     "milcon"      "milaid"     
[11] "intcom"  

When i navigate to the package proper ("/home/andresgannon/R/x86_64-pc-linux-gnu-library/4.2/peacesciencer") in /extdata/ I don't see atop, which is odd given it's able to load the alliance level version of the data, hm.

@jandresgannon
Copy link
Author

jandresgannon commented Mar 24, 2023

Potentially helpful, install the github version of the package and rebooting R seems to solve the problem. The example in the original post now runs. That did not require me to run download_extdata() either (although I got the prompt).

EDIT: that did not solve the problem. Re-running it now causes the same error. Will keep finicking with it

@svmiller
Copy link
Owner

svmiller commented Mar 25, 2023

That might sound accusatory, but do you have something in session that is loading alliance-level ATOP data as atop_alliance after you loaded the package? That's the only thing I could think of that's happening here, because nothing in this package makes use of the alliance-level data for either CoW or ATOP (not even download_extdata(), which doesn't download anything about alliances). Alliance data in the package are only dyad-year. Given the documentation files and CRAN's burdensome quality controls, I couldn't get this on CRAN if atop_alliance didn't 100% match the information provided about it in the documentation file.

@jandresgannon
Copy link
Author

Ah yup, that was my mistake. I messed up having my own alliance df loaded as atop_alliance in the chunk prior to loading peacesciencer. Error is entirely on my end.

Much thanks for your help!

@svmiller
Copy link
Owner

Glad that was it! Fortunately this was resolved, but it's a good experience for me to note the limitations of something like this as a software bundle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants