xlsx
xlsx copied to clipboard
Bug for exporting when using multiple criterias with summarise(group_by()) clause
Hi,
I'm using your great package but I'm experiencing an issue when generating a dataframe with 2 criterias on group_by instruction
The following code :
analyse_all = summarise(group_by(data, DCLT), total=round(sum(IPONDI)))
analyse_all = arrange(analyse_all, desc(total))
write.xlsx2(analyse_all, outpufile, sheetName=sheetname, col.names=TRUE, row.names=TRUE, append=TRUE)
returns a valid XLS sheet.
But the following do not - see screenshot below :
# Total par Communes - groupement
analyse_com = summarise(group_by(data, COMMUNE, DCLT), total=round(sum(IPONDI)))
analyse_com = arrange(analyse_com, desc(total))
write.xlsx2(analyse_com, outpufile, sheetName=paste(sheetname,"COM", sep="_"), col.names=TRUE, row.names=TRUE, append=TRUE)

Could you tell me why ?
Analysing dataset does not show any problem ! Thanks for your support
> head(analyse_all)
# A tibble: 6 x 2
`Commune de destination` `Total des déplacements`
<int> <dbl>
1 35360 10558
2 35238 2567
3 35125 2183
4 35068 2162
5 35006 1640
6 35109 1521
> head(analyse_com)
# A tibble: 6 x 3
# Groups: COMMUNE [5]
COMMUNE DCLT total
<int> <int> <dbl>
1 35360 35360 4681
2 35125 35125 901
3 35068 35068 808
4 35006 35006 718
5 35068 35238 608
6 35015 35360 472
I was able to solve that bug by declaring explicitly a data.frame.See code below (line 3) :
analyse_com = summarise(group_by(data, COMMUNE, DCLT), NOM_COM=unique(NOM_COM), NOM_DCLT=unique(NOM_DCLT), total=round(sum(IPONDI)))
analyse_com = arrange(analyse_com, desc(total))
analyse_com = data.frame(analyse_com) # !!!!! Here is the workaround !!!!!
write.xlsx2(analyse_com, outpufile, sheetName=paste(sheetname,"COM", sep="_"), col.names=TRUE, row.names=TRUE, append=TRUE)
Would be nice to handle this inside the library itself ! thanks
Related to #73