@@ -110,51 +110,92 @@ Leave the man page from the previous step in place so that
110110
111111still shows the list of defunct functions and their appropriate replacements.
112112
113- ## How To Deprecate A Package Dataset {#deprecate-dataset}
113+ ## How To Deprecate An S3 Dataset {#deprecate-dataset}
114114
115- ### Step 1 - Save a promise object
115+ ### Step 1 - Create an S3 deprecation class
116116
117- The initial step of deprecating a dataset is to signal to any users on
118- the devel branch of Bioconductor that the dataset will no longer be used.
119- This can be done using a ` warning ` message when the devel user loads
120- the dataset. In order to do this, we first create a promise object with
121- the same name as the dataset name using the ` delayedAssign ` function:
117+ The initial step of deprecating a dataset is to signal to users that the
118+ dataset will no longer be used. Alert the user with a ` warning ` message added to
119+ its ` print ` method. To do this, first add the deprecation class to the dataset
120+ object. Note that the class name here is arbitrary but it should be descriptive:
122121
123- delayedAssign(
124- x = "pkgDataset",
125- value = {
126- warning("'pkgDataset' dataset is deprecated; see '?newData'")
127- pkgDataset
128- }
129- )
122+ class(pkgDataset) <- c("DeprecatedData", class(pkgDataset))
130123
131- You can also include the dataset as an output after the warning.
132- We then replace the original ` .Rda ` dataset file in the package with the
133- promise object and dataset using the ` save ` function:
124+ Then serialize the class as an R object so that it can be loaded in the
125+ package:
134126
135- save(" pkgDataset", eval.promises = FALSE, file = "data/pkgDataset.Rda ")
127+ save(pkgDataset, file = "data/pkgDataset.rda ")
136128
137- With the ` eval.promises ` argument set to ` FALSE ` , we can delay the evaluation
138- of the promise object until the user loads the data with
139- ` data("pkgDataset", package = "yourPkg") ` . The user will then get a warning
140- along with the dataset. The warning should include instructions that will point
141- the user to a new dataset or functionality that will replace the data, if
142- necessary.
129+ or with ` usethis ` :
143130
144- ### Step 2 - Update documentation
131+ usethis::use_data(pkgDataset, overwrite = TRUE)
145132
146- After the promise object has been saved, we update the documentation to
133+ ### Step 2 - Create a print method
134+
135+ Then create a print method for the new class that will print the warning
136+ message:
137+
138+ print.DeprecatedData <- function(x, ...) {
139+ warning("'pkgDataset' dataset is deprecated; see '?newData'")
140+ NextMethod()
141+ }
142+
143+ It is useful to guide the user to the replacement dataset or functionality
144+ that will replace the data in the ` warning ` message. Note that this method
145+ should be exported in the package's ` NAMESPACE ` file.
146+
147+ ### Step 3 - Update documentation
148+
149+ After the dataset object has been saved, we update the documentation to
147150reflect the changes and provide additional details and resources for
148151users as necessary. It is recommended to include a "[ ; Deprecated] ; " label
149152in the data documentation title.
150153
151- ### Step 3 - Defunct the dataset
154+ ### Step 4 - Defunct the dataset
155+
156+ In the following release cycle, upgrade the warning message to an error
157+ message to indicate that it is no longer available. The data can then be
158+ removed from the package. Remember to update the "[ ; Deprecated] ; "
159+ label in the documentation title to "[ ; Defunct] ; ".
160+
161+ ## How to Deprecate An S4 Dataset
162+
163+ ### Step 1 - Create an S4 deprecation class
164+
165+ With S4, the process is similar to S3, but we need to create a new class
166+ that inherits from the original class with ` setClass ` . The class name here
167+ is arbitrary but should be descriptive:
168+
169+ .DeprecatedData <-
170+ setClass("DeprecatedData", contains = "S4Class")
171+
172+ The ` setClass ` call creates a generator function which we can then use
173+ to create an instance of the new class from the old object:
174+
175+ myS4DataObject <- .DeprecatedData(myS4DataObject)
176+
177+ We then serialize the object to disk so that it can be loaded in the
178+ package:
179+
180+ save(myS4DataObject, file = "data/myS4DataObject.rda")
181+
182+ or by using ` usethis ` :
183+
184+ usethis::use_data(myS4DataObject, overwrite = TRUE)
185+
186+ ### Step 2 - Create a show method
187+
188+ Create a ` show ` method for the new class that will produce a warning message:
189+
190+ setMethod("show", "DeprecatedData", function(object) {
191+ warning("This dataset is deprecated; see '?newData'")
192+ callNextMethod()
193+ })
194+
195+ Note that this method should be exported in the package's ` NAMESPACE ` and
196+ the ` show ` generic should be imported from the ` methods ` package.
152197
153- In the following release cycle, you can update the warning message to indicate
154- that the dataset is defunct and remove it entirely from the promise object
155- i.e., from the expression in the ` delayedAssign ` function. We can also update
156- the "[ ; Deprecated] ; " label in the documentation title to
157- "[ ; Defunct] ; ".
198+ Note that steps 3 and 4 are the same as for S3 datasets.
158199
159200## How to Deprecate a Package {#deprecate-package}
160201
0 commit comments