-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# nocov start --- compat-linked-version --- 2020-02-24 Mon 12:55 CET | ||
|
||
|
||
check_linked_version <- local({ | ||
|
||
howto_reinstall_msg <- function(pkg) { | ||
os <- tolower(Sys.info()[["sysname"]]) | ||
|
||
if (os == "windows") { | ||
url <- "https://github.com/jennybc/what-they-forgot/issues/62" | ||
c( | ||
i = sprintf("Please update %s to the latest version.", pkg), | ||
i = sprintf("Updating packages on Windows requires precautions:\n <%s>", url) | ||
) | ||
} else { | ||
c( | ||
i = sprintf("Please update %s with `install.packages(\"%s\")` and restart R.", pkg, pkg) | ||
) | ||
} | ||
} | ||
|
||
function(pkg, with_rlang = requireNamespace("rlang")) { | ||
ver <- utils::packageVersion(pkg) | ||
|
||
ns <- asNamespace(pkg) | ||
linked_ver_ptr <- ns[[paste0(pkg, "_linked_version")]] | ||
if (is.null(linked_ver_ptr)) { | ||
linked_ver <- "" | ||
} else { | ||
linked_ver <- .Call(linked_ver_ptr) | ||
} | ||
|
||
if (nzchar(linked_ver) && ver == linked_ver) { | ||
return(invisible(NULL)) | ||
} | ||
|
||
header <- sprintf("The %s package is not properly installed.", pkg) | ||
|
||
if (nzchar(linked_ver)) { | ||
msg <- c(x = sprintf( | ||
"The DLL version (%s) does not correspond to the package version (%s).", | ||
linked_ver, | ||
ver | ||
)) | ||
} else { | ||
# Package does not have a version pointer. This happens when DLL | ||
# updating fails for the first version that includes the pointer. | ||
msg <- c(x = "The DLL version does not correspond to the package version.") | ||
} | ||
|
||
msg <- c(msg, howto_reinstall_msg(pkg)) | ||
|
||
if (with_rlang) { | ||
msg <- paste(header, rlang::format_error_bullets(msg), sep = "\n") | ||
rlang::abort(msg) | ||
} else { | ||
msg <- paste(c(header, msg), collapse = "\n") | ||
stop(msg, call. = FALSE) | ||
} | ||
} | ||
}) | ||
|
||
|
||
# nocov end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#define R_NO_REMAP | ||
#include <Rinternals.h> | ||
|
||
const char* rlang_version = "0.4.4.9000"; | ||
|
||
/** | ||
* This file records the expected package version in the shared | ||
* library (or DLL) of the package. This is useful to check that users | ||
* have properly installed your package. Installation issues where the | ||
* package is updated but the DLL isn't are common on Windows in | ||
* particular. To automatically check that the native library of the | ||
* package was properly installed: | ||
* | ||
* - Register the function below as a C callable under the name | ||
* "rlang_linked_version". | ||
* | ||
* - Call `rlang::check_linked_version(pkg_name)` from your | ||
* `.onLoad()` hook. If you don't depend on rlang copy the | ||
* compat-linked-version.R file from the rlang repository to your R | ||
* folder. Find it at | ||
* <https://github.com/r-lib/rlang/tree/master/R/compat-linked-version.R> | ||
*/ | ||
|
||
// [[ register() ]] | ||
SEXP rlang_linked_version() { | ||
return Rf_mkString(rlang_version); | ||
} |