Repository navigation
Initialise create.legend.labels so guideline = FALSE draws its legend - #60
Merged
braverock merged 1 commit intoSep 19, 2026
Merged
Conversation
chart.EfficientFrontierCompare() builds create.legend.labels only inside the
guideline block, and then uses it unconditionally:
if(guideline){
...
create.legend.labels <- paste("% Increase in Risk =", ...)
create.legend.labels <- append(create.legend.labels, paste("% Increase in Return =", ...))
}
...
if(is.null(legend.labels)){
legend.labels <- paste("min", match.col, "Portfolio")
legend.labels <- append(legend.labels, create.legend.labels)
}
With guideline = FALSE and legend.labels left at its default, the function
stops with
object 'create.legend.labels' not found
before anything is drawn. guideline defaults to TRUE only when two entries are
given in match.col, so the failing path is the ordinary one for a single
frontier, and it is also reachable with two.
NULL is the right empty value rather than character(0) or a placeholder:
append() drops it, which leaves one label per match.col, and that is exactly
the number of colours, line types and widths the guideline = FALSE branch sets
a few lines above. Measured, on four edhec columns with two match.col:
guideline = TRUE master: 4 labels, 4 colours this branch: identical
min StdDev Portfolio | min ES Portfolio |
% Increase in Risk = 10.44 | % Increase in Return = 11.78
guideline = FALSE master: error this branch: 2 labels, 2 colours
min StdDev Portfolio | min ES Portfolio
The labels were captured by tracing graphics::legend, so this is what the
function actually passes, not what it looks like it should.
No test is added or changed. tests/testthat/test-charts-roi.R already asserts
this exact behaviour in two tests, "guideline=FALSE produces no error" and
"legend.loc non-NULL branch produces no error", and both currently fail. That
file goes from 67 passing with 2 failures to 69 passing with none.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
The change resolves the reported error while preserving existing guideline behavior.
Pull request overview
Fixes chart.EfficientFrontierCompare() when guideline = FALSE and default legend labels are used.
Changes:
- Initializes
create.legend.labelstoNULL. - Preserves guideline labels and keeps legends aligned with plotted frontiers.
File summaries
| File | Description |
|---|---|
R/charts.efficient.frontier.R |
Prevents the missing-object error during legend construction. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
chart.EfficientFrontierCompare()stops withwhenever
guideline = FALSEandlegend.labelsis left at its default. Nothingis drawn; the error comes from the legend block at the end.
create.legend.labelsis built only inside the guideline block, and then usedunconditionally:
guidelinedefaults toTRUEonly whenmatch.colhas two entries, so thefailing path is the ordinary one for a single frontier, and it is reachable with
two as well by passing
guideline = FALSE.The change
One line:
create.legend.labels <- NULLbefore the guideline block, with acomment saying why.
NULLrather thancharacter(0)or a placeholder, becauseappend()drops it.That leaves one label per
match.col, which is exactly the number of colours,line types and widths the
guideline = FALSEbranch sets a few lines above, sothe legend stays consistent with the lines it describes.
Measured
Four
edheccolumns,match.col = c("StdDev", "ES"), labels captured bytracing
graphics::legend, so this is what the function passes rather than whatit looks like it should:
masterguideline = TRUEguideline = FALSEWith
guideline = TRUEboth builds pass the same four labels:min StdDev Portfolio,min ES Portfolio,% Increase in Risk = 10.44,% Increase in Return = 11.78.Tests
None added, none changed.
tests/testthat/test-charts-roi.Ralready assertsthis behaviour in two tests,
chart.EfficientFrontierCompare: guideline=FALSE produces no errorandchart.EfficientFrontierCompare: legend.loc non-NULL branch produces no error, and both currently fail.test-charts-roi.RmasterTest suite
masterNo failures left. The two errors are the
objective()tests intest-objective-branches.R, which #61 fixes; measured there, that filegoes to 33 passing with none. The two changes touch different files, so between
them the four problems
run-all.Rreports are accounted for.Why this one and #61 are worth taking first
R-CMD-checkandtest-coveragehave both been red onmastersince 24 July,and both die at the same step,
running the tests in 'run-all.R' failed. Whatrun-all.Rreports there is four problems: the two fixed here, and two intest-objective-branches.R, whereROImasksobjective()in a full-suiterun. #61 fixes those.
With both merged, that step passes and the pipeline is green again. I can only
see that the workflows stop at that step, so if something else is broken behind
it, it is hidden by these four rather than absent.
This matters for the five pull requests that are already open, because their
checks are red for this reason and not for theirs. They do not need rebasing:
the workflows run on
pull_requestandactions/checkout@v4checks out themerge commit, so once
mastercarries these two fixes, re-running the jobs oneach of them is enough.
Scope
One file, 7 insertions, of which 6 are the comment. This change stands on its
own and does not depend on any other.
🤖 Generated with Claude Code