How to Include Data in Your R Package
HTML-код
- Опубликовано: 21 авг 2024
- Including data in an R package can be very useful. Here we create an R package from scratch that offers a function to calculate a user-defined customer score from strictly defined variable names. To showcase the function, we need data, so we include an example dataset in the package and document it using roxygen tags. Data documentation is somewhat different to function documentation. We use the great usethis package for our convenience.
To find out more, read the great R Packages book by Hadley Wickham and Jenny Bryan: r-pkgs.org/ind...
Contact me, e. g. to discuss (online) R workshops / trainings / webinars:
LinkedIn: / wolfriepl
Twitter: / statistikindd
Xing: www.xing.com/p...
Facebook: / statistikdresden
statistik-dres...
R Workshops: statistik-dres...
Blog (German, translate option): statistik-dres...
Playlist: Music chart history
• Music Chart History
Very helpful. thank you!
Simple and easy to understand. Nice explanation
Thanks, quick and easy to follow. Best,
Nice. This was really handy!
I like that video. I have a question is it possible to add data from a package (which is not mine) to t? If possible, then how?
You can add any data that you can get in the Global Environment.
If it is already in a package, you may also add that package to Suggests or Imports.
So how: load data into Global Environment. Then proceed as in video.
I'm just not sure if I'd like the same data in different packages. But there may be situations where it makes sense. E. g. to avoid dependency on that other package, maybe because it contains a lot more than the data, or because it is difficult to access in your environment.
How do you document the dataset if you are reading in a csv file?
Good question. As far as I know, data documentation works for R objects. csv is a non-native format from R's perspective.
Some packages contain data (as R-native objects) and additionally make the same data available in .csv or .tsv format, like palmerpenguins and gapminder.
r-pkgs.org/data.html#sec-data-extdata
Thanks alot! This has been absolutely helpful. But how do i push this now to github? Or how do i create a new package project and link it to github?
If it's not a local project, make it one. In RStudio, you can use the "New Project" option in the projects menu in the top right corner.
If it's a local project, but without a git repository, create one. You can use usethis::use_git() to that end.
If it's a local project with a git repository that is not yet on github, you can push it there using usethis::use_github(). Check the help page to see about the options, e. g. how to make it a private repository.
@@StatistikinDD aha! thanks for the ultra-fast answer. gonna test it tonight...
Why do you waste so much time on explaining what the function inhouse_calc does? No one cares it scales, no one cares it's not exactly between 0 and 100, etc. The video title says this is about including data in your R package so it would be better to focus on that and leave everything distracting aside.
Thanks for your comment, Robert. I'll try to stick more to the point next time.
@@StatistikinDD Clearly explained and straight to point. Saved me a lot of time just by watching this video. Thank you!
You have a very logical point but some information about other stuff comes with main topic's wind. You don't just go from point a to b. You also see where the supermarket on your way to point b. This kind of informations is crucial for some people, and showing it with a realistic and alive example is also important. You can simply skip it. Anyways. Great tutorial @StatistikinDD keep it rooling!