简体   繁体   中英

Why plyr's join_all function causes r to crash?

I want to join multiple dataframes by using plyr's join_all function. My dataframes consist of three columns each, and they all have the same amount of rows. When I run the code, r is not able to finish its job; the whole computer lags and I have to restart it.

Here is the code that I've used:

library(plyr)

merge_corp_inv_count_noavg <- join_all(list(canada,china,france,germany,india,italy,japan,russia,saudiarabia,
                                      spain,turkey,unitedkingdom,unitedstates),
                                 by = c("date", "target_nation"), type='left')

I have used this code in the past and it has worked, although the dataframes included more columns then. Nonetheless it is still confusing that it doesn't work now.

Any ideas why it causes r to crash?

Here is a list of packages that I have loaded:

library(tidyverse)
library(readxl)
library(tm)
library(tidyr)
library(data.table)
library(convertr)
library(dplyr)
library(stringr)
library(zoo)
library(runner)
library(ggplot2)

Perhaps any of these clash with plyr's function join_all?

I am seriously afraid of running that code again as it wastes some 30 minutes of my time; so please provide answers if you're more or less certain. Thanks.

If things were working earlier and suddenly crashed, it is better to check the datasets. With join, there is a likelihood of some datasets having duplicates for the key columns and this could trigger a cartesian join instead of left join, and thus creates memory issues.


An option using tidyverse would be

library(dplyr)
library(purrr)
list(canada, china, france, germany, india, italy, japan, russia, saudiarabia,
                                  spain, turkey, unitedkingdom, unitedstates) %>%
   reduce(left_join, by = c("date", "target_nation"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM