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

support for several axis calls on same side #410

Merged
merged 11 commits into from
Oct 27, 2016

Conversation

jordansread
Copy link
Member

No description provided.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.08%) to 79.445% when pulling 800cb05 on jread-usgs:master into bc8f472 on USGS-R:master.

# remove
if (length(which.axis) > 1){
# remove all axis functions other than the first one
object[[as.side_name(side)]] <- object[[as.side_name(side)]][-which.axis[!which.axis %in% head(which.axis, 1)]]

Choose a reason for hiding this comment

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

I was thinking you'd want to remove everything but the last one

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm...we should discuss the expected behavior for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ldecicco-USGS and @jiwalker-usgs do you have thoughts on this?

Copy link
Member Author

Choose a reason for hiding this comment

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

My reasoning was this:
using the append arg to get multiple axis calls in there means appending them to the original call, which is the default set-up when the side is created. When you then set append = FALSE (what it is checking for here), those appended axis calls are wiped out.

I can see your point too, where you would want to treat it like append was FALSE the whole time and use the last, but that isn't the same behavior either.

For example:

gs <- gsplot() %>% 
    points(0:1,0:1) %>% 
    axis(side=1, at=c(0.5,1), labels=FALSE) %>% 
    axis(side=1, at=c(0.25, 0.75), line = 2, append=TRUE) %>% 
    axis(side=1, at=c(0.45, 0.55), lwd = 2, append=TRUE) %>% 
    axis(side=1, at=c(0.33))

the last call uses append = FALSE, so what does that mean? Ignore all of the other TRUE calls and treat them as FALSE (collapsing all of their arguments into one), or does it mean remove all appended axis calls and build off of the default (what it currently does)?

Copy link

@lindsayplatt lindsayplatt Oct 27, 2016

Choose a reason for hiding this comment

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

I would think in that example the last axis call replaces everything above it since it does not have append.

gs <- gsplot() %>% 
    points(0:1, 0:1) %>% 
    axis(side=1, at=c(0.5, 1)) %>% 
    axis(side=1, at=c(0.25, 0.75), line = 2, append=TRUE) %>% 
    axis(side=1, at=c(0.45, 0.55), lwd = 2, append=TRUE) %>% 
    axis(side=1, at=c(0.33))
gs

Creates
image

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, that is what happens now with this PR

Copy link

@lindsayplatt lindsayplatt Oct 27, 2016

Choose a reason for hiding this comment

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

hmmm I guess your comment says " remove all axis functions other than the first one" and that makes me think that everything except axis(side=1, at=c(0.5, 1)) is removed. Nevermind if it's removing all except axis(side=1, at=c(0.33))!

which.axis <- which(names(object[[side.name]]) == 'axis')
if (length(which.axis) > 1){
for (axis.i in which.axis){
tmp <- object

Choose a reason for hiding this comment

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

what's the purpose of creating tmp?

Copy link
Member Author

Choose a reason for hiding this comment

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

this was kind of a hack to deal with multiple axis function calls in one object. tmp is the same object, but w/o the other axis calls, that way I can pass tmp back into the same function and it will be treated the same way a single axis object is. Make sense? This function in general needs some attention, and I just added some new junk to it.

Choose a reason for hiding this comment

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

Hmmm I think I understand, but isn't tmp changing each time from the new axis on the next line?

Copy link
Member Author

Choose a reason for hiding this comment

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

the next line just has it remove all of the other axis calls in tmp. This loops through the axis calls and tmp is re-created each time based on the original object.

Copy link
Member Author

Choose a reason for hiding this comment

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

the object[[as.side_name(side)]][['axis']] <- append_replace(object[[as.side_name(side)]][['axis']], user_args[[fun.name]]) append_replace makes sure the new arguments override the existing ones.

axis(side=1, at=c(0.25, 0.75), append=TRUE) %>%
axis(side=1, at=c(0.45, 0.55), append=TRUE) %>%
axis(side=1, at=c(0.33))
expect_equal(sum(names(gs$side.1) == 'axis'), 1)

Choose a reason for hiding this comment

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

any way to add a test for making sure it's keeping the expected axis and dropping the others?

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea @lindsaycarr I will add that

Copy link
Member Author

Choose a reason for hiding this comment

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

added it

Copy link
Member Author

Choose a reason for hiding this comment

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

@lindsaycarr can you merge if you think this is good to go?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.08%) to 79.445% when pulling dcea59f on jread-usgs:master into bc8f472 on USGS-R:master.

@lindsayplatt lindsayplatt merged commit a83420b into USGS-R:master Oct 27, 2016
@lindsayplatt
Copy link

lindsayplatt commented Oct 27, 2016

fixing #408

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.

3 participants