Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw error when same argument is passed to aes and geom #119

Merged
merged 7 commits into from
Mar 26, 2024

Conversation

siddhesh195
Copy link
Contributor

Throw error when same argument is passed to aes and geom
Closes #110

Because of the change, the test "empty data overrides plot defaults" would always error out since it aes(mpg, wt) is passed along with x,y to plot

@siddhesh195 siddhesh195 requested review from tdhock and Faye-yufan March 7, 2024 04:16
Copy link
Collaborator

@tdhock tdhock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great thanks!

@tdhock
Copy link
Collaborator

tdhock commented Mar 7, 2024

please add a NEWS item and increase version number.

@tdhock
Copy link
Collaborator

tdhock commented Mar 7, 2024

Can you please add a test for geom(aes(alpha),alpha_off) ?

@siddhesh195
Copy link
Contributor Author

siddhesh195 commented Mar 13, 2024

Can you please add a test for geom(aes(alpha),alpha_off) ?

Added test for geom(aes(alpha),alpha_off). This required additional changes to match _off parameters. Also, moved the validation checks to geom-.r from layer.r

R/geom-.r Outdated
result <- sub(pattern, "", input_string)
return(result)
} else {
return("")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is simpler to not use return
also this whole function could be replaced by grep(input_string, pattern, value=TRUE)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I rewrote the check using grep and sub and the whole function is not required anymore

)
expect_error({
animint2dir(viz, open.browser=FALSE)
}, "Same argument cannot be passed to both aes and geom. Argument passed to both aes and geom: alpha")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please change the error message? it is not true that alpha was passed to both aes and geom, because alpha_off was passed to geom.
Also it would be good to explain why the same argument cannot be used / how to fix: the visual property needs only be defined in one place, so if the alpha should be different for each rendered geom, but not depend on selection state, then use aes(alpha); but if the alpha should depend on the selection state then use geom(alpha,alpha_off).
and actually for this test to make more sense with alpha_off, you would need to add clickSelects="some_selection_variable" so that the alpha_off could actually be used.
In fact could you please add another test for an error message when alpha_off is used in a geom without clickSelects? that should be a different error (alpha_off defines the opacity of geoms with clickSelects, but are not currently selected, so please fix by removing alpha_off or adding clickSelects)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the error message to distinguish between alpha and alpha_off. Is the new error message better to understand for the user ?

Added a new test without clickSelects and alpha_off and verified that the correct warning is displayed. When aplha_off is used without clickSelects, currently a warning is thrown. Does it make more sense to throw an error instead ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently if there are multiple errors, one error masks the others since the compiler stops upon an error. Maybe this can be modified to throw multiple errors before stopping when its possible to continue compilation. gcc/llvm do that and continue compilation to discover additional errors

)
expect_warning({
animint2dir(viz, open.browser=FALSE)
}, "geom1_path_plot has alpha_off which is not used because this geom has no clickSelects; please specify clickSelects or remove alpha_off")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

@tdhock tdhock merged commit 0169301 into master Mar 26, 2024
5 checks passed
@tdhock
Copy link
Collaborator

tdhock commented Mar 26, 2024

thanks very much for this useful contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

error in compiler when aes used at same time as param
2 participants