I am writing some re-usable (hopefully) R code, and part of it is a pglm helper function:
pglm_helper <- function(family, fmla, fixed_effect, tbl) {
pglm::pglm(
fmla,
family=family,
data=tbl,
effect="individual",
model="within",
index=fixed_effect
)
}
However, it tries to pass in "fixed_effect" as the index, not the string the symbol represents. If I pass in the correct string or create a global variable with fixed_effect <<- fixed_effect, this works.
pglm_helper <- function(family, fmla, fixed_effect, tbl) {
pglm::pglm(
fmla,
family=family,
data=tbl,
effect="individual",
model="within",
index="pair_id"
)
}
However, once I get index to work, it complains about tbl being a function, as well as family. In fact, even running this:
model_3_4_pois <- function(my_tbl) {
pglm::pglm(
cites ~
as.factor(year)
+ as.factor(age)
+ is_brc_window
+ is_brc_post_deposit,
family="poisson",
data=my_tbl,
effect="individual",
model="within",
index="article_id"
)
}
It can't find my_tbl.
It appears as though this function completely ignores the local environment; is there anyway to get this function evaluate the local environment?