I am pretty new to R programming. Can someone please help me here?
This question has already been answered here but rbindlist is having certain limitations hence want some different approach: For each item in Dataframe want to loop automatically
I want to create a network graph between the warehouses:
Here in the input data, each item can be shipped from LC to an ToLC and these LCs are interlinked also. For each item with the different combination of connection between the warehouses we need the output.
input data:
    library(data.table)
lctolc <- fread("
Item     LC     ToLC
8T4121  AB12    BC34
8T4121  MN12    AB12
8T4121  MW92    WK14
8T4121  WK14    RM11
8T4121  WK14    RS11
8T4121  RS11    OY01
AB7651  MW92    RS11
AB7651  RS11    OY01",
data.table = FALSE)
Here, in the input table we can see:
For Item 8T4121 we have warehouse connection as AB12->BC34 and in next line we have warehouse connection as MN12->AB12
So this should be warehouse MN12->AB12->BC34
Similarly, we have MW92->WK14 and WK14->RM11 and WK14->RS11 and RS11->OY01
So this should make two lanes MW92->WK14->RM11 and MW92->WK14->RS11->OY01
Output should be like below:
     Item  LC1  LC2  LC3  LC4
1: 8T4121 MN12 AB12 BC34 <NA>
2: 8T4121 MW92 WK14 RS11 OY01
3: 8T4121 MW92 WK14 RM11 <NA>
4: AB7651 MW92 RS11 OY01 <NA>
Till now what I have tried:
library(data.table)
bodlane <- lapply(
  lapply(split(lctolc, lctolc$Item), function(x) graph.data.frame(x[, 2:3])), 
  function(x) lapply(
    V(x)[degree(x, mode = "in") == 0], 
    function(s) all_simple_paths(x, from = s, 
                                 to = V(x)[degree(x, mode = "out") == 0]) %>% 
      lapply(
        function(y) as.data.table(t(names(y))) %>% setnames(paste0("LC", seq_along(.)))
      ) %>% 
      rbindlist(fill = TRUE) 
  ) %>% rbindlist(fill = TRUE)
) %>% rbindlist(fill = TRUE, idcol = "Item")
When I am running this code for large dataset I am getting the below mentioned error:
Error in rbindlist(., fill = TRUE, idcol = "Item"): attempt to set index 50611/50611 in SET_STRING_ELT

