jthaman / ciTools

An R Package for Quick Uncertainty Intervals
GNU General Public License v3.0
106 stars 9 forks source link

Incorrect warning messages #10

Closed aldaniello closed 6 years ago

aldaniello commented 6 years ago

Example: newDF <- add_ci(test, testModel, alpha = 0.1, names = c(“LCB”, “UCB”))

If test does not have the columns pred, LCB, and UCB, no warning appears. (Expected outcome: no warning [working as expected]) If I rerun the exact same line and am overwriting newDF, no warning appears (Expected outcome: should get warning)

If I run the following: test <- add_ci(test, testModel, alpha = 0.1, names = c(“LCB”, “UCB”)) newDF2 <- add_ci(test, testModel, alpha = 0.1, names = c(“LCB”, “UCB”))

I get a warning that I am overwriting data in newDF2, even though that df is created in that line and does not yet exist. (Expected outcome: no warning)

It seems that the warning only occurs when the dataframe defined in the function has the columns of the same name even though the warning should occur when the dataframe written to has columns of the same name.

matthewravery commented 6 years ago

These warnings are working as intended, so I'm closing this issue.

The functions in ciTools are designed to take an existing data frame and augment it. In the example you give, the data frame test already has columns named "LCB" and "UCB". Thus, the warning message is alerting you that you've overwritten columns from the data frame you started with.

The functionality may be more intuitive if you think about it using the pipe operator. Re-writing your code:

newDF2 <- test %>% add_ci(testModel, alpha = 0.1, names = c("LCB", "UCB"))

This code reads, "Take the data table test and add a confidence interval to it. Call this newDF2." If test has no columns named "LCB" and "UCB", no warning occurs. If test already has columns named "LCB" and "UCB", a warning is produced.