Hi listers,


I have a package asremlPlus on CRAN that manipulates formulae. It uses the 
keep.order argument, as in the stats::terms function, to allow control over the 
order of terms in a model.



However, when stats::update.formula is used to update a formula, there is no 
keep.order argument for update.formula. The result is that the updated formula 
is always simplified to a sum of single terms and these terms are always 
re-ordered. I have written a function that is able to update a formula and keep 
the order. The following example illustrates the problem and my solution.



#Functions to keep.order when a formula is updated

update_keep_order <- function(object, ...) {

  UseMethod("update_keep_order")

}

update_keep_order.formula <- function(old, new, keep.order = TRUE) {

  tmp <- .Call(stats:::C_updateform, as.formula(old), as.formula(new))

  formula(terms.formula(tmp, keep.order = keep.order, simplify = TRUE))

}



#Generate some factors and a formula

facs <- expand.grid(A=1:2, B=1:2, C=1:2, D=1:2)

form <- with(facs, formula(~ A*B + C*D))



#Update with update.formula

(upd <- update(form, ~ . - C, keep.order = TRUE))



#Update with update_keep_order.formula

(upd_keep <- update_keep_order(form, ~ . - C, keep.order = TRUE))



However, the function calls the undocumented function stats::C_updateform and 
so cannot be added to my package.



Is there another solution to achieve this outcome that does not require this 
undocumented function and so could be incorporated in an R package on CRAN?



Thanks in advance for any help in solving this issue.



Cheers,



  Chris


        [[alternative HTML version deleted]]

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to