Correctly handle date attributes in list format in 'get.edgelist.with.timestamps' - #289
Conversation
Correct implementations of 'get.edgelist.with.timestamp' should retain the structure of listed edges and the POSIXct type of dates. Signed-off-by: Maximilian Löffler <s8maloef@stud.uni-saarland.de>
|
Thanks for this PR @maxloeffler. I did not spot anything to criticize and would directly approve it. However, seems like you have been too slow 🙈 🙃 The test suite fails because of some errors in the plotting functionality (which is completely unrelated to this PR). Unfortunately, the plotting library we use ( Sorry for the additional effort, but you are the perfect guy for dealing with such issues – you have already lots of experience with stuff like that 🥲 |
|
No problem ^^ I've looked into the problem and it's actually quite interesting. Disclaimer: While I figured out where the problem lies and could fix it for older and newer Run downSo in plotting there is this function ggraph::scale_edge_linetype(name = "Relation Types")This scale_edge_linetype <- function(..., na.value = 'blank') {
sc <- scale_linetype(..., na.value = na.value)
sc$aesthetics <- 'edge_linetype'
sc
}
scale_linetype <- function(name = waiver(), ..., aesthetics = "linetype") {
discrete_scale(
aesthetics, name = name,
palette = NULL,
...
)
}Problem and FixAs you can see, the final call to ggplot2::discrete_scale(name = "Relation Types", aesthetics = "edge_linetype", palette = scales::pal_linetype())For this call, I defaulted to using the standard palette that |
I did: This commit introduced I've checked the issues of Ultimate SolutionThank you very much for coming up with a fix in a relatively short period of time, good work! While this fix might potentially work as a temporary fix, I don't think we should generally fix Temporary fixNot sure how fast |
|
I would assume that this is a problem with What I do not know is what the reason behind the I'll follow your suggestion to integrate the temporary fix for now and see about opening a PR soon. |
When the parameter is TRUE timestamps in the edgelist returned by 'get.edgelist.with.timestamps' will be into vector. Unlisting fails if the input network contains simplified edges. Signed-off-by: Maximilian Löffler <s8maloef@stud.uni-saarland.de>
|
(Side note: I updated the |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #289 +/- ##
==========================================
+ Coverage 82.55% 82.57% +0.01%
==========================================
Files 16 16
Lines 5378 5378
==========================================
+ Hits 4440 4441 +1
+ Misses 938 937 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
No worries, I also don't understand what the reason behind the In addition, could you please update your copyright header in |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes handling of date attributes in list format for the get.edgelist.with.timestamps function and adds an optional parameter to allow unlisting timestamps when possible.
- Updates
get.edgelist.with.timestampsto correctly handle date attributes in both vector and list formats - Adds
unlist.timestamps.if.possibleparameter to control timestamp format in return value - Includes comprehensive test coverage for the new functionality
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| util-plot.R | Workaround for bug in ggraph scale functions by using ggplot2 directly |
| util-misc.R | Enhanced get.edgelist.with.timestamps with new parameter and list handling logic |
| tests/test-misc.R | Added comprehensive test coverage for both vector and list date formats |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
As discussed in PR#289, 'graph::scale_edge_linetype' produces a scale with 'palette' = NULL. Upon printing the resulting plot (as done in 'showcase.R') this invalid palette causes the following error: "Cannot convert `x` to discrete palette" We can fix the problem temporarily by creating the scale manually through 'ggplot2::discrete_scale' and setting the palette to the default linetype palette. Signed-off-by: Maximilian Löffler <s8maloef@stud.uni-saarland.de>
|
Looks good now. The analysis script that previously has thrown an error in Could you please update the NEWS now? We should add an item for the fix there if this bug was already caused by changes of the previous release of coronet. If the bug was not present in the last release, just add the commit hash to the item that describes the changes in which we have wrapped the dates in lists without further description. Adding a new parameter to the function, however, may need a separate entry below the one which is related to first commit. And last but not least: As already mentioned above, could you please draft a bug report for the issue that you have figured out in |
Signed-off-by: Maximilian Löffler <s8maloef@stud.uni-saarland.de>
|
Dates are lists since release 5.0 so this change must receive a "fix entry". The other workaround you mentioned in plotting is an interesting case. It was introduced 7 years ago and was seemingly never anything more than a comment that suggests on how to do it "correctly". Therefore, it also does not receive any explicit mention in the NEWS which I think is also correct because this is not a change that must be externally communicated. |
Drafted Bug ReportHey ggplot team, I stumbled upon an error in the scale_linetype function and its internal invocation of Error in `as_discrete_pal()`:
! Cannot convert `x` to a discrete palette.Note, however, that the error does not occur if library(igraph)
library(ggraph)
library(ggplot2)
library(scales)
network = igraph::make_graph(c("A", "B"))
# works
plot = ggraph::ggraph(network)
plot = plot + ggplot2::scale_linetype(aesthetics = "linetype")
print(plot)
# works
plot = ggraph::ggraph(network)
plot = plot + ggplot2::scale_linetype()
print(plot)
# works
plot = ggraph::ggraph(network)
plot = plot + ggplot2::discrete_scale(aesthetics = "edge_linetype", palette = scales::pal_linetype())
print(plot)
# breaks
plot = ggraph::ggraph(network)
plot = plot + ggplot2::scale_linetype(aesthetics = "edge_linetype")
print(plot) |
bockthom
left a comment
There was a problem hiding this comment.
@maxloeffler Thanks for all the updates, and also thanks a lot for drafting the bug report (which we will discuss in our meeting).
I can approve this PR now and I will certainly merge it right after our discussion of the bug-report draft for the ggplot2 bug.
|
@bockthom I overhauled the drafted bug report. I mentioned the discussed case in text and included all properly working cases in code as well |
|
Thanks @maxloeffler for updating the drafted bug report! I will report it to |
Prerequisites
showcase.Rwith respect to my changes.dev.Description
In #274, we changed the default representation of edge attributes from vectors to lists. During this transition, the
get.edgelist.with.timestampsmethod was updated properly. Here, we update the method to work correctly with dates in either vector or list format. Also, we add a newunlist.timestamps.if.possibleparameter to the method to allow callers to assert that timestamps in the return value ofget.edgelist.with.timestampsare vectors instead of listsChangelog
Added
unlist.timestamps.if.possibleparameter toget.edgelist.with.timestampsto allow callers to receive timestamps in vector format instead of list format (when possible)Fixed
get.edgelist.with.timestamps