You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can use an object in a formula for selecting rows, e.g.:
library(flextable)
dfr<-data.frame(value= c("a", "b", "c"))
## row selection formula uses object in global environment## this worksmake_b_bold<-"b"dfr|>
flextable() |>
bold(i=~value%in%make_b_bold)
But attempting this inside a function leads to an error:
## row selection formula uses object in function environmentmake_table<-function(){
make_c_bold<-"c"dfr|>
flextable() |>
bold(i=~value%in%make_c_bold)
}
make_table()
#> Error in value %in% make_c_bold: object 'make_c_bold' not found
I think this is due to the environment in which the function is evaluated does not have the function environment as a parent?
I can work around this in a few ways, e.g. by creating the logical vector rather than using a formula:
## row selection uses object in function environment## this worksmake_table2<-function(){
make_bold<-dfr$value%in%"c"dfr|>
flextable() |>
bold(i=make_bold)
}
make_table2()
But maybe there is a better way to do this type of thing? Or a way to make the object available to the row selection formula?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I can use an object in a formula for selecting rows, e.g.:
But attempting this inside a function leads to an error:
I think this is due to the environment in which the function is evaluated does not have the function environment as a parent?
I can work around this in a few ways, e.g. by creating the logical vector rather than using a formula:
But maybe there is a better way to do this type of thing? Or a way to make the object available to the row selection formula?
Beta Was this translation helpful? Give feedback.
All reactions