I want to know the simple and short procedure to add dataset in my own R package. I tried to follow https://www.youtube.com/watch?v=Bj0gHafa4GE but after that I don't know why data is not appearing in R. As package successfully uploaded in CRAN named as "DEEVD". If I write
> data(Rhone)
Warning message:
In data(Rhone) : data set ‘Rhone’ not found
I have no idea where I missed the connection because during R-CMD check there is no error and data help files worked perfectly. Kindly guide me and write in comment section if any further detail is required. Edit: the answer of @Mossa is very useful But it works correctly in Rstudio. When I updated my Package in CRAN there is same problem. It can be examined after downloading DEEVD
Alright, I can finally answer.
The issue is what is written in your src/Rhone.R file.
Here you are redefining Rhone. That's not what this file is supposed to contain.
Instead this file src/Rhone.R is supposed to contain documentation for the dataset Rhone.
#' Documentation for `Rhone` should reside here.
#'
#'
"Rhone"
Now, here's how I solved it.
First, open the package as a project in Rstudio.
Then (if you don't have it already) install {usethis} package via install.packages("usethis").
Then run usethis::use_data_raw("Rhone"). You can read the documentation of
this function, to know what it does:
> usethis::use_data_raw("Rhone")
√ Setting active project to
[REDACTED]
√ Creating 'data-raw/'
√ Adding '^data-raw$' to '.Rbuildignore'
√ Writing 'data-raw/Rhone.R'
* Modify 'data-raw/Rhone.R'
* Finish the data preparation script in 'data-raw/Rhone.R'
* Use `usethis::use_data()` to add prepared data to package
Now, go to the data-raw/Rhone.R file, and put the definition of `Rhone in there.
At the end, data-raw/Rhone.R should look like this:
## code to prepare `Rhone` dataset goes here
Rhone <-
c(
1355,
1492,
1692,
1766,
1903,
2040,
2177,
2314,
2451,
2588,
2725,
2862,
2999,
3136,
3273,
3410,
3547,
3686,
3822,
3959,
4096,
4233,
4370
)
usethis::use_data(Rhone, overwrite = TRUE)
Run/source this script. This now saves a file named Rhone.rda to the data/-folder.
Now, when you build your package, then this data-file is the only file that is
connected with the name Rhone. And not a redefinition of it, as what happened before.
If you change the definition of Rhone, then you have to re-run/re-source data-raw/Rhone.R. But you only have to do that if you change Rhone. And you only can change Rhone inside of data-raw/Rhone.R. Nowhere else is it possible to change Rhone.
If you build and load your package, then the code you used before will work.
> library(DEEVD)
> data(Rhone)
> Rhone
[1] 1355 1492 1692 1766 1903 2040 2177 2314 2451 2588
[11] 2725 2862 2999 3136 3273 3410 3547 3686 3822 3959
[21] 4096 4233 4370
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With