Skip to content

[R-pkg-devel] Changes in function call with respect to the current published version

6 messages · Jose Barrera-Gómez, Georgi Boshnakov, John Fox

#
Dear List,

I have a package that works in the context of regression models. The main
function has arguments (y, x, z, data, ...), where y is the response
variable, x is the explanatory variable and z can be other covariates.

Due to some bugs, I am interested in changing the call from (y, x, z, data,
...) to (formula, data, ...).

For instance, current usage is

myfun(y = birthweight, x = cotinine, z = age, data = mydata, ...)

and new usage would be

myfun(formula = birthweight ~ cotinine + age, data = mydata, ...)

This change would have no impact on the usage for the rest of the package.

My concern is that users updating the package won't be able to reproduce
old analyses. I.e. they would need to update the calls to myfun (but
nothing else related to the usage of other functions or methods).

I think the new usage would result in some advantages and bugs fixing and
only the disadvantage I mentioned just above.

I would appreciate advice on:

1) There could be other disadvantages for users of previous versions that I
don't see?

2) What would be the best location(s) in the documentation to explain in
detail this change?

Thanks in advance,

Jose Barrera
Statistician, Associate Lecturer

*IS**Global*
Barcelona Institute for Global Health - Campus MAR
Barcelona Biomedical Research Park (PRBB) (Room Hypatia)

Doctor Aiguader, 88
08003 Barcelona, Spain
Tel. +34 93 2147383
jose.barrera at isglobal.org
<https://www.linkedin.com/in/josebarrera>
Personal website: sites.google.com/view/josebarrera
www.isglobal.org

This message is intended exclusively for its addressee and may contain
information that is CONFIDENTIAL and protected by professional privilege.
If you are not the intended recipient you are hereby notified that any
dissemination, copy or disclosure of this communication is strictly
prohibited by law. If this message has been received in error, please
immediately notify us via e-mail and delete it.

DATA PROTECTION. We inform you that your personal data, including your
e-mail address and data included in your email correspondence, are included
in the ISGlobal Foundation filing system. Your personal data will be used
for the purpose of contacting you and sending information on the activities
of the above foundations. You can exercise your rights to  access to
personal data, rectification, erasure, restriction of processing, data
portability and object by contacting the following address: *lopd at isglobal.org
<lopd at isglobal.org>*. ISGlobal Privacy Policy at *www.isglobal.org
<http://www.isglobal.org/>*.


-----------------------------------------------------------------------------------------------------------------------------

CONFIDENCIALIDAD. Este mensaje y sus anexos se dirigen exclusivamente a su
destinatario y puede contener informaci?n confidencial, por lo que la
utilizaci?n, divulgaci?n y/o copia sin autorizaci?n est? prohibida por la
legislaci?n vigente. Si ha recibido este mensaje por error, le rogamos lo
comunique inmediatamente por esta misma v?a y proceda a su destrucci?n.

PROTECCI?N DE DATOS. Sus datos de car?cter personal utilizados en este
env?o, incluida su direcci?n de e-mail, forman parte de ficheros de
titularidad de la Fundaci?n ISGlobal  para cualquier finalidades de
contacto, relaci?n institucional y/o env?o de informaci?n sobre sus
actividades. Los datos que usted nos pueda facilitar contestando este
correo quedar?n incorporados en los correspondientes ficheros, autorizando
el uso de su direcci?n de e-mail para las finalidades citadas. Puede
ejercer los derechos de acceso, rectificaci?n, supresi?n, limitaci?n del
tratamiento, portabilidad y oposici?n dirigi?ndose a *lopd at isglobal.org
<lopd at isglobal.org>* . Pol?tica de privacidad en *www.isglobal.org
<http://www.isglobal.org/>*.
#
The NEWS file should state this incompatible change, loudly.

If you don't want to break user code, you could make the new signature of the function something like:

myfun(formula, data = mydata, ..., y, x, z)

Then you could start with 

if(!is.formula(formula)) {
    issue a message that this is old syntax;

    create a formula for the user from the arguments
}

You need this check since users often don't name the first argument. The purpose of putting y,x, and z after the ... is so that you will have arguments with these names only if the user explicitly named them so.

In the new documentation function describe only the new usage and state that the old arguments are for back compatibility only and will be removed in version x.y.

Georgi Boshnakov
#
Of course, it should be
With no default for 'data'.

Georgi Boshnakov

-----Original Message-----
From: R-package-devel <r-package-devel-bounces at r-project.org> On Behalf Of Georgi Boshnakov
Sent: 17 December 2024 22:34
To: Jose Barrera-G?mez <jose.barrera at isglobal.org>; R Package Development <r-package-devel at r-project.org>
Subject: Re: [R-pkg-devel] Changes in function call with respect to the current published version
The NEWS file should state this incompatible change, loudly.

If you don't want to break user code, you could make the new signature of the function something like:

myfun(formula, data = mydata, ..., y, x, z)

Then you could start with 

if(!is.formula(formula)) {
    issue a message that this is old syntax;

    create a formula for the user from the arguments }

You need this check since users often don't name the first argument. The purpose of putting y,x, and z after the ... is so that you will have arguments with these names only if the user explicitly named them so.

In the new documentation function describe only the new usage and state that the old arguments are for back compatibility only and will be removed in version x.y.

Georgi Boshnakov
#
Dear Jose,

Assuming that you can fix the bugs in the original function, one 
approach would be to make myfun() generic, say myfun <- function(y, ...) 
UseMethod("myfun"), with the (fixed) original myfun() as the default 
method and a new function method, which would probably set up a call to 
the default method. Then existing code wouldn't break and users would 
have the option of using a formula.

I hope this helps,
  John
#
Dear Jose,
On 2024-12-18 10:26 a.m., John Fox wrote:
That should read "a new formula method" (not "a new function method").

Sorry for the confusion,
  John
#
Hi Georgi, Uri, John and List,

Thank you, that was very helpful!

Kind regards

Jose Barrera
Statistician, Associate Lecturer

*IS**Global*
Barcelona Institute for Global Health - Campus MAR
Barcelona Biomedical Research Park (PRBB) (Room Hypatia)

Doctor Aiguader, 88
08003 Barcelona, Spain
Tel. +34 93 2147383
jose.barrera at isglobal.org
<https://www.linkedin.com/in/josebarrera>
Personal website: sites.google.com/view/josebarrera
www.isglobal.org

This message is intended exclusively for its addressee and may contain
information that is CONFIDENTIAL and protected by professional privilege.
If you are not the intended recipient you are hereby notified that any
dissemination, copy or disclosure of this communication is strictly
prohibited by law. If this message has been received in error, please
immediately notify us via e-mail and delete it.

DATA PROTECTION. We inform you that your personal data, including your
e-mail address and data included in your email correspondence, are included
in the ISGlobal Foundation filing system. Your personal data will be used
for the purpose of contacting you and sending information on the activities
of the above foundations. You can exercise your rights to  access to
personal data, rectification, erasure, restriction of processing, data
portability and object by contacting the following address: *lopd at isglobal.org
<lopd at isglobal.org>*. ISGlobal Privacy Policy at *www.isglobal.org
<http://www.isglobal.org/>*.


-----------------------------------------------------------------------------------------------------------------------------

CONFIDENCIALIDAD. Este mensaje y sus anexos se dirigen exclusivamente a su
destinatario y puede contener informaci?n confidencial, por lo que la
utilizaci?n, divulgaci?n y/o copia sin autorizaci?n est? prohibida por la
legislaci?n vigente. Si ha recibido este mensaje por error, le rogamos lo
comunique inmediatamente por esta misma v?a y proceda a su destrucci?n.

PROTECCI?N DE DATOS. Sus datos de car?cter personal utilizados en este
env?o, incluida su direcci?n de e-mail, forman parte de ficheros de
titularidad de la Fundaci?n ISGlobal  para cualquier finalidades de
contacto, relaci?n institucional y/o env?o de informaci?n sobre sus
actividades. Los datos que usted nos pueda facilitar contestando este
correo quedar?n incorporados en los correspondientes ficheros, autorizando
el uso de su direcci?n de e-mail para las finalidades citadas. Puede
ejercer los derechos de acceso, rectificaci?n, supresi?n, limitaci?n del
tratamiento, portabilidad y oposici?n dirigi?ndose a *lopd at isglobal.org
<lopd at isglobal.org>* . Pol?tica de privacidad en *www.isglobal.org
<http://www.isglobal.org/>*.


El mi?, 18 dic 2024 a las 18:37, John Fox (<jfox at mcmaster.ca>) escribi?: