sinhrks / ggfortify

Define fortify and autoplot functions to allow ggplot2 to handle some popular R packages.
Other
527 stars 65 forks source link

Support survfit objects with multiple stratification variables. Fixes #214 #215

Closed KellenBrosnahan closed 3 years ago

KellenBrosnahan commented 3 years ago

In fortify_surv.R, changed the regular expression on line 49 to be "[^,]=" instead of ".=". This is in response to Issue #214, and the change is meant to allow autoplot to work on survfit objects with multiple stratification variables.

testResults.txt

KellenBrosnahan commented 3 years ago

I'm not quite sure what you mean by that. Do you mean that I should add an additional test to the test-all.R file?

terrytangyuan commented 3 years ago

Yes an additional test under /tests that covers this extra case/regex would be great.

KellenBrosnahan commented 3 years ago

I've never used the testthat package before. Is there a guide for using it? Also, I should be adding the test to the test-surv.R file in the testthat folder, correct?

KellenBrosnahan commented 3 years ago

Here's the test I'm trying to add.

test_that('fortify.survfit regular expression for renaming strata works with multiple stratification variables', {
  skip_if_not_installed("survival")
  library(survival)
  d.survfit <- survival::survfit(Surv(time, status) ~ sex + ph.ecog, data = lung)
  fortified <- ggplot2::fortify(d.survfit)
  expect_equal(is.data.frame(fortified), TRUE)
  expected_names <- c('time', 'n.risk', 'n.event', 'n.censor', 'surv',
                      'std.err', 'upper', 'lower', 'strata')
  expect_equal(names(fortified), expected_names)
  expect_equal(length(fortified$strata), 8)
})

When I run test-all.R with this test included, it fails, and it gives the expected error message under the current version of ggfortify. Is this because the ggfortify package hasn't incorporated the fix yet?

KellenBrosnahan commented 3 years ago

@terrytangyuan, is there anything left to do for this?

terrytangyuan commented 3 years ago

You are all set. You can try the GitHuh version for now until the new version is on CRAN.