Skip to content

Instantly share code, notes, and snippets.

@jsta
Created September 28, 2020 19:27
Show Gist options
  • Save jsta/4b8be3f41da11ee11c08523cba73c129 to your computer and use it in GitHub Desktop.
Save jsta/4b8be3f41da11ee11c08523cba73c129 to your computer and use it in GitHub Desktop.
Verify that adding ability to pass model number as a variable doesn't cause rloadest output changes
library(rloadest)
my_model_no <- 1
loadreg_original <- loadReg(Phosphorus ~ model(1),
data = app1.calib, dates = "DATES", flow = "FLOW")
loadreg_mod <- loadReg(as.formula(paste0("Phosphorus ~ model(", my_model_no, ")")),
data = app1.calib, dates = "DATES", flow = "FLOW")
identical(
loadreg_original,
loadreg_mod
)
# FALSE
identical(coef(loadreg_mod$cfit),
coef(loadreg_original$cfit))
# TRUE
(whats_changed <- names(loadreg_original)[
!unlist(
lapply(seq_len(length(loadreg_mod)),
function(i) identical(
loadreg_original[[i]],
loadreg_mod[[i]]))
)
])
# [1] "lfit" "cfit"
(what_changed_cfit <- names(loadreg_original$cfit)[
!unlist(
lapply(seq_len(length(loadreg_mod$cfit)),
function(i) identical(
loadreg_original$cfit[[i]],
loadreg_mod$cfit[[i]]))
)
])
# [1] "call" "terms"
identical(
loadreg_mod$cfit$call,
loadreg_original$cfit$call
)
# FALSE
loadreg_mod$cfit$call
# loadReg(formula = as.formula(paste0("Phosphorus ~ model(", my_model_no,
# ")")), data = app1.calib, flow = "FLOW", dates = "DATES")
loadreg_original$cfit$call
# loadReg(formula = Phosphorus ~ model(1), data = app1.calib, flow = "FLOW",
# dates = "DATES")
@jsta
Copy link
Author

jsta commented Sep 28, 2020

Printing loadreg_mod with brief=FALSE doesn't error but it does give some strange output:

print(loadreg_mod, brief = FALSE)
...
Selected Concentration Model:
-----------------------------

as.formula(paste0("Phosphorus ~ model(", my_model_no, ")"))

where:
   paste0("Phosphorus ~ model(", my_model_no, ")") is the constituent concentration in log(mg/L)
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment