Adding a nickname to an R package? - r

When developping an R package, is it possible to add a nickname to a certain version?
How would this be added in the DESCRIPTION file?
That cannot be in the version, as only numbers are accepted. It could of course be in the description, but it would not be a real metadata.

You can add a field to the DESCRIPTION file for this:
Package: coolpkg
Nickname: Coolest Nickname Ever
Version: 0.1.0
After installing your package you can then get the nickname back like this:
packageDescription("coolpkg")[["Nickname"]]
FYI I think CRAN has standards around what can go in the DESCRIPTION file, just something to keep in mind if that's what you're working towards.
Alternatively, you could just save the nickname as a data object in the package.

Related

Create "on this page" section in RBookdown

I've noticed that many books built using RBookdown will have an "on this page" section in the upper right hand corner (displays book subsections). You can see what I'm referring to by looking at Hadley Wickham's "R4DS" book here: https://r4ds.had.co.nz/data-visualisation.html.
After digging through the source code I can't figure out how to create this section. Does anyone know how this section is created?
They are using a new document format bookdown::bs4_book. This new format renders the section in question. See the rdrr.io man page for some more information.
To use the new format, first install the latest bookdown version from github with remotes::install_github("rstudio/bookdown"). Then you can specify the new format for your bookdown project in your _output.yaml file like they have done here.
Note, there are a number of dependencies required to use the new format including downlit, bslib, and notably a version of htmltools >= 0.5.0.9001. downlit can be installed with remotes::install_github("r-lib/downlit") while bslib can be installed with remotes::install_github("rstudio/bslib"), and one would normally be able to install htmltools with just remotes::install_github("rstudio/htmltools"). However, as of this writing the latest version of htmltools is failing its R-CMD-Check, and I was unable to install it on my system. Therefore, I installed the 0.5.0.9001 version by referencing the requisite commit with remotes::install_github("rstudio/htmltools#8c82cc4f869f75ac4f13ee78ab322790ec316d3f").

Replacing the vignette with a new version

I submitted an R Package to CRAN a couple of months back which is currently available as a package. I submitted the vignette along with the package. Now I have an updated version of my vignette which I need to replace with the old vignette. How to proceed?
I checked in How to put a link to another vignette in the same R package in a vignette
but that lacks clarity to what I'm looking for.
Please help. Thanks.
PS. I have a PDF file of the vignette

R package choroplethr says use zip_choroplethr instead of zip_map, but function not available

I did install.packages("choroplethr"), followed by library(choroplethr). I want to find out how to do a zip code choropleth, so I start typing in RStudio,
"?choroplethr::zip..." The only function that RStudio finds is zip_map. I go to its help file and see the following documentation:
This function is deprecated as of choroplethr version 3.0.0. Please
use ?zip_choropleth instead. The last version of choroplethr in which
this function worked was version 2.1.1, which can be downloaded from
CRAN here:
http://cran.r-project.org/web/packages/choroplethr/index.html
Okay, I guess I'll find out about this zip_choroplethr function then.
?choroplethr::zip_choroplethr
# No documentation for ‘zip_choroplethr’ in specified packages and libraries:
# you could try ‘??zip_choroplethr’
Wut.
Thank you for using choroplethr.
zip_map is, indeed, deprecated. It used scatterplots, which wasn't the best way to visualize zip codes, especially because they are so small.
Within choroplethr, Zip code choropleths are managed by a new, separate package: choroplethrZip. You can see the installation instructions and documentation here.
CRAN rejected choroplethrZip due to the size of the map, which is why it is in separate package and on github.

How do I add a Changelog or NEWS file to my R package?

I have a package on CRAN that I would like to add a ChangeLog for, but I cannot find information anywhere on how to do this.
I looked on the "Writing R Extensions" document that CRAN provides, but it only mentions ChangeLogs and gives no direction (I could find) about how to create one.
I noticed from downloading tarballs from other packages on CRAN (e.g. seacarb) that their ChangeLogs are Unix Executable Files (I'm on a Mac) so that's not too helpful.
I imagine this is a common problem, but Googling "changelog R package" just brings up ChangeLogs for really popular packages...
You can either provide a NEWS file or a ChangeLog file, or both, to describe changes in your package. You have to add these files in the top level folder of your project, i.e. in the same folder as your DESCRIPTION and NAMESPACE.
This is documented in the R package manual in paragraph 1.1 Package structure. In particular, this paragraph points to the GNU standard:
For the conventions for files NEWS and ChangeLog in the GNU project see http://www.gnu.org/prep/standards/standards.html#Documentation.
Hadley points out that "Generally you should use a NEWS file, and not ChangeLog. I think the purpose of ChangeLog (to list every change), has been subsumed by source code control".
To create a NEWS file, simply create a text file called NEWS in the top level folder of your package. You maintain this file by hand.
Here is an extract from the NEWS file from my package miniCRAN (CRAN link):
miniCRAN v0.0-21 (Release date: 2014-08-18)
==============
Changes:
* Changes to defaults in plot.pkgDepGraph() to move legend to left of plot area.
miniCRAN v0.0-20 (Release date: 2014-08-18)
==============
Changes:
* Modified examples to reduce running time, mostly using \dontrun{} sections
NEWS.md files are now also supported by CRAN (Which renders them as html) and more recently by the news() function.
https://cran.r-project.org/doc/manuals/r-devel/NEWS.html
If you are following this and opting for NEWS.md then make sure news() reads the same correctly (at the same time it looks great on GitHub).
You can do the same in your local builds of the packages.
It seems like it has a specific format you have to adhere with.
I tried like this (and it works) (check here)
# *News*
# tidycells 0.1.9 (2019-07-31)
## Initial Submission
* **CRAN** Initial Submission
# tidycells 0.1.5 (2019-07-30)
## Final Codebase Release in GitHub
* Final Release in GitHub for **CRAN** Submission
* Only Minor Documentation Change after this and before next **CRAN** Submission
# tidycells 0.1.0 (2019-07-25)
## Initial Release to GitHub
* Initial Release to GitHub
* Prior to this it was private package

cover function (?) : how to deal with dependencies packages while developing new package in r

My the R package depends upon other package (for example "fields")
What is best practice to ensure that the package is loaded, when my package is loaded.
Should I write cover r program to do this ? Can or should such dependencies distributed with my distribution ?
I will appreciate a detail answer with scrips
Edit:
As per following suggestion I added the following in Discription file.
Depends: R (>= 1.8.0), fields
Still the fields package is not loaded automatically when I load my package.
This is something you specify in your DESCRIPTION file that you ship with your package. You can use either the 'Depends' field, or better is to use 'Imports' field in combination with a NAMESPACE file. Have a look at the DESCRIPTION and NAMESPACE files from some other packages, or read over the Writing R Extensions manual.

Resources