Open johan-ejstrud opened 4 months ago
ChatGPT is probably right, but isn't this kind of error message already what R is doing?
Examples
but that is a general starter warning - it always slips my eyes - like advertisements. Perhaps improved if thrown only when needed. that is if gt::px is actually in r-script?
chatGPT says:
Yes, you can create a custom error message for a name clash between pxmake::px and gt::px in your package. You can add checks to detect if gt is loaded and if gt::px has been masked by pxmake::px. Here’s a simple approach to add this check when your package is loaded.
Step 1: Create an .onLoad() function Add an .onLoad() function in your package’s main file (e.g., zzz.R), which will execute when the package is loaded. Inside this function, you can check for potential name clashes.
r Kopier kode .onLoad <- function(libname, pkgname) {
Check if
gt
is loadedif ("package:gt" %in% search()) {
Check if
gt::px
has been masked bypxmake::px
} } Step 2: Test the Behavior Install and load your package alongside gt and ensure that the warning message appears if there’s a name conflict. This approach will give your users a clear indication of the conflict and provide them with guidance on how to resolve it.