shenwei356 / csvtk

A cross-platform, efficient and practical CSV/TSV toolkit in Golang
http://bioinf.shenwei.me/csvtk
MIT License
992 stars 84 forks source link

Join with some empty files #266

Open fgvieira opened 6 months ago

fgvieira commented 6 months ago

Prerequisites

Describe your issue

Input files:

$ echo -e "f,c1\n1,2" > 1.csv
$ echo -e "f,c2\n3,4" > 2.csv
$ echo -e "f,c3" > 3.csv

Two first files works fine:

$ csvtk join -f f --na NA --outer-join 1.csv 2.csv 
f,c1,c2
1,2,NA
3,NA,4

But when including the empty file:

$ csvtk join -f f --na NA --outer-join 1.csv 2.csv 3.csv 
[WARN] no data found in file: 3.csv
f,c1,c2
1,2,NA
3,NA,4

it does not show! Any way that it shoes up, but just all NAs? For example:

f,c1,c2,c3
1,2,NA,NA
3,NA,4,NA
shenwei356 commented 6 months ago

Sorry, it's not easy to fix this in a short time. I'm busy recently.

Here's a workaround solution -- creating columns that are missed.

$ csvtk join -f f --na NA --outer-join 1.csv 2.csv 3.csv \
    | csvtk mutate2 -n c3 -e '"NA"'
[WARN] no data found in file: 3.csv
f,c1,c2,c3
1,2,NA,NA
3,NA,4,NA