giocomai / ganttrify

Create beautiful Gantt charts with ggplot2
https://ganttrify.europeandatajournalism.eu/
GNU General Public License v3.0
654 stars 61 forks source link

Error when wp and activity in the same wp have exact same name #48

Closed BenJCQuah closed 7 months ago

BenJCQuah commented 7 months ago

Hi, thanks for your great gantt plot package.

I have the older and newer versions (0.0.0 and 0.0.1) of this package and the newer version appears to have a bug (?) in dplyr:::mutate.data.frame. Please see below the trace to the error. This same code/dataframe appears to work well in the older version.

Please let me know if you need more info.

Thanks!

ganttrify::ganttrify(project = kg_plan) Registered S3 method overwritten by 'wesanderson': method from
print.palette MetBrewer Error in dplyr::mutate(): ℹ In argument: activity = factor(x = activity, levels = level_labels_df$levels). Caused by error in levels<-: ! factor level [41] is duplicated Run rlang::last_trace() to see where the error occurred. rlang::last_trace() <error/dplyr:::mutate_error> Error in dplyr::mutate(): ℹ In argument: activity = factor(x = activity, levels = level_labels_df$levels). Caused by error in levels<-: ! factor level [41] is duplicated

Backtrace: ▆

  1. ├─ganttrify::ganttrify(project = kg_plan, )
  2. │ └─... %>% dplyr::arrange(activity)
  3. ├─dplyr::arrange(., activity)
  4. ├─dplyr::mutate(., activity = factor(x = activity, levels = level_labels_df$levels))
  5. ├─dplyr:::mutate.data.frame(., activity = factor(x = activity, levels = level_labels_df$levels))
  6. │ └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
  7. │ ├─base::withCallingHandlers(...)
  8. │ └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
  9. │ └─mask$eval_all_mutate(quo)
  10. │ └─dplyr (local) eval()
  11. └─base::factor(x = activity, levels = level_labels_df$levels) Run rlang::last_trace(drop = FALSE) to see 3 hidden frames.
giocomai commented 7 months ago

I've been working on a new version, which should also provide more meaningful error messages, so it's possible that some bug appeared, but all examples in the readme work fine, so I'd need more information to figure out what is the problem here.

Ideally, you would provide a "minimal reproducible example" , or probably just a version of your original data frame with all personal data removed would allow me to troubleshoot this further.

Also, when you're reporting this make sure you're using the latest version (and you can of course return to a previous version later until this is fixed)

BenJCQuah commented 7 months ago

Sorry, yes I should have added a few things to clarify and an example. This occurs if your data entries in wp and activity are identical (I want a blank line where I place the current data text as it moves across the chart over time). The error occurs in the latest version and not version 6f7a4384e57688fb5b92f699d13c7957fe97e4fb.

As an example here is the code and some data attached (just "current date" in both wp and activity, and start_date and end_date 1 and 24 respectively:

INSTALL PACAKGES

remotes::install_github("giocomai/ganttrify") #here it errors remotes::install_github("giocomai/ganttrify@6f7a4384e57688fb5b92f699d13c7957fe97e4fb") #here it doesn't install.packages("MetBrewer")

LOAD PACKAGES

library(ganttrify) library(tidyverse) library(MetBrewer)

ASSIGN AND LOAD DATA

test <- read.csv("test.csv")

PLOT

ganttrify::ganttrify(project = test)

gives

ASSIGN AND LOAD DATA

test <- read.csv("test.csv") Warning message: In read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'test.csv'

PLOT

ganttrify::ganttrify(project = test) Error in dplyr::mutate(): ℹ In argument: activity = factor(x = activity, levels = level_labels_df$levels). Caused by error in levels<-: ! factor level [2] is duplicated Run rlang::last_trace() to see where the error occurred.

test.csv

giocomai commented 7 months ago

All clear, thanks. Fix coming in a few seconds. Update then to the latest version and you should be good to go. Do let me know if you encounter further issues.

library("ganttrify")
project <- tibble::tribble(
  ~wp, ~activity, ~start_date, ~end_date,
  "example", "example", 1, 6,
  "example", "different", 3,12
)

ganttrify::ganttrify(project)

Created on 2024-02-09 with reprex v2.1.0