Skip to content

Commit

Permalink
fix: update dcast usage by making sure all data are preserved
Browse files Browse the repository at this point in the history
* Return single value in `dcast.data.table()`. Required in `data.table` > 1.5. Fixes #94
Replace use of fun.aggregate argument of dcast with dummy variable in dataset for when x has duplicate values.
Method as described here: https://rdatatable.gitlab.io/data.table/reference/rowid.html
* doc: Clean up comments old code commented out.
* feat: improved version that keeps all of user's data.

fix #94
---------

Co-authored-by: Jan Marvin Garbuszus <[email protected]>
Co-authored-by: David Gohel <[email protected]>
  • Loading branch information
3 people authored Apr 26, 2024
1 parent 68b3808 commit da9fb75
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mschart
Type: Package
Title: Chart Generation for 'Microsoft Word' and 'Microsoft PowerPoint' Documents
Version: 0.4.0
Version: 0.4.1.001
Authors@R: c(
person("David", "Gohel", role = c("aut", "cre"),
email = "[email protected]"),
Expand Down Expand Up @@ -31,6 +31,6 @@ Imports: stats, data.table,
htmltools, utils
URL: https://ardata-fr.github.io/officeverse/, https://ardata-fr.github.io/mschart/
BugReports: https://github.com/ardata-fr/mschart/issues
RoxygenNote: 7.2.2
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
Suggests: tinytest, doconv
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ importFrom(cellranger,as.range)
importFrom(cellranger,cell_limits)
importFrom(cellranger,ra_ref)
importFrom(cellranger,to_string)
importFrom(data.table,":=")
importFrom(data.table,.N)
importFrom(data.table,as.data.table)
importFrom(data.table,dcast.data.table)
importFrom(data.table,rbindlist)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# mschart 0.4.1

## Issues

* fix issue with dcast by making sure all data are preserved.

# mschart 0.4.0

## New features
Expand Down
11 changes: 4 additions & 7 deletions R/excel_series.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ transpose_data <- function(data, vars, group) {
}


#' @importFrom data.table := .N
dcast_data <- function(data, x, y, group) {
dataset <- as.data.table(data)
form_str <- sprintf("%s ~ %s", x, group)
dataset <- dataset[, c(".fake_id.") := list(seq_len(.N)), by = c(x, group)]
form_str <- sprintf("%s + .fake_id. ~ %s", x, group)
out <- dcast.data.table(
dataset,
formula = as.formula(form_str),
fun.aggregate = function(x) {
x
},
fill = NA, value.var = y
)
out$.fake_id. <- NULL
setDF(out)
out
}
Expand Down Expand Up @@ -96,9 +96,6 @@ transpose_series_bysplit <- function(x) {






#' @importFrom stats as.formula
#' @importFrom data.table as.data.table dcast.data.table setorderv setnames
shape_as_series <- function(x) {
Expand Down
2 changes: 1 addition & 1 deletion man/mschart.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit da9fb75

Please sign in to comment.