diff --git a/DESCRIPTION b/DESCRIPTION index bbb645da..40e36ec5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: fistools Title: Tools & data used for wildlife management & invasive species in Flanders -Version: 1.2.19 +Version: 1.2.20 Authors@R: c( person(given = "Sander", middle = "", family = "Devisscher", "sander.devisscher@inbo.be", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2015-5731")), @@ -38,5 +38,6 @@ Imports: mapview (>= 2.11.2), osmdata (>= 0.2.5), readr (>= 2.1.5), + RCurl (>= 1.98.1.16), tcltk, aws.s3 (>= 0.3.21) diff --git a/NAMESPACE b/NAMESPACE index 3ab9c44f..b78ed080 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,6 +13,7 @@ export(connect_to_bucket) export(download_dep_media) export(download_gdrive_if_missing) export(download_seq_media) +export(install_depricated) export(install_sp) export(label_converter) export(label_selecter) diff --git a/R/install_depricated.R b/R/install_depricated.R new file mode 100644 index 00000000..8f9572d7 --- /dev/null +++ b/R/install_depricated.R @@ -0,0 +1,70 @@ +#' install depricated package +#' +#' Helper function that installs depricated package when missing, from a tarball. +#' +#' @param package_name A character string indicating the name of the package to be installed +#' @param version A character string indicating the version of the package to be installed +#' @param force A logical indicating whether the installation should be forced +#' +#' @details +#' Sometimes a package is depricated and no longer available on CRAN. +#' This function allows you to install a depricated package from a tarball. +#' It is recommended to use this function only when necessary. +#' In first instance try to find an alternative package. +#' Using depricated packages may cause conflicts and unexpected behaviour. +#' +#' @importFrom utils install.packages +#' +#' @export +#' @family other +#' @examples +#' \dontrun{ +#' # install latest version of sp package instead of install_sp() +#' install_depricated("sp", "2.1-3") +#' # trying to install a wrong version of maptools +#' install_depricated("maptools", "2.1-3", force = TRUE) +#' +#' } +#' +#' @author Sander Devisscher + +install_depricated <- function(package_name, + version, + force = FALSE) { + if (!rlang::is_installed(package_name)) { + message(paste0(package_name, " is not installed, installing it now")) + # download the tarball from CRAN https://cran.r-project.org/src/contrib/Archive/sp/sp_2.1-3.tar.gz + # and place it in a temporary directory + # create url + version_url <- paste0("https://cran.r-project.org/src/contrib/Archive/", package_name, "/", package_name, "_", version, ".tar.gz") + + # test url + test_version_url <- RCurl::url.exists(version_url) + + # create tempfile + tempfile <- tempfile() + + # download the tarball if url exists + if(test_version_url == FALSE){ + warning(paste0(package_name, " version ", version, " is not available on CRAN")) + package_url <- paste0("https://cran.r-project.org/src/contrib/Archive/", package_name) + test_package_url <- RCurl::url.exists(package_url) + + if(test_package_url == TRUE ){ + if(askYesNo("You are trying to install a non existing version of the package. Do you want to browse the CRAN Archive to look up a usable version?") == TRUE){ + browseURL(paste0("https://cran.r-project.org/src/contrib/Archive/", package_name)) + } + } else { + stop("The package is not available on the CRAN archive") + } + } else { + download.file(version_url, destfile = tempfile) + } + + # install the tarball + install.packages(tempfile, repos = NULL, type = "source", force = force) + } + if(rlang::is_installed(package_name) == TRUE){ + print(paste0(package_name, " is installed \U0001F389")) + } +} diff --git a/R/install_sp.R b/R/install_sp.R index e1b514d3..df9de29a 100644 --- a/R/install_sp.R +++ b/R/install_sp.R @@ -13,6 +13,7 @@ #' @importFrom utils install.packages #' #' @export +#' @family other #' #' @author Sander Devisscher diff --git a/docs/404.html b/docs/404.html index 4837a40c..3ff45a18 100644 --- a/docs/404.html +++ b/docs/404.html @@ -20,7 +20,7 @@ fistools - 1.2.19 + 1.2.20 + + + + + +
+
+
+ +
+

Helper function that installs depricated package when missing, from a tarball.

+
+ +
+

Usage

+
install_depricated(package_name, version, force = FALSE)
+
+ +
+

Arguments

+ + +
package_name
+

A character string indicating the name of the package to be installed

+ + +
version
+

A character string indicating the version of the package to be installed

+ + +
force
+

A logical indicating whether the installation should be forced

+ +
+
+

Details

+

Sometimes a package is depricated and no longer available on CRAN. +This function allows you to install a depricated package from a tarball. +It is recommended to use this function only when necessary. +In first instance try to find an alternative package. +Using depricated packages may cause conflicts and unexpected behaviour.

+
+
+

See also

+

Other other: +install_sp(), +label_selecter()

+
+
+

Author

+

Sander Devisscher

+
+ +
+

Examples

+
if (FALSE) { # \dontrun{
+# install latest version of sp package instead of install_sp()
+install_depricated("sp", "2.1-3")
+# trying to install a wrong version of maptools
+install_depricated("maptools", "2.1-3", force = TRUE)
+
+} # }
+
+
+
+
+ + +
+ + + + + + + diff --git a/docs/reference/install_sp.html b/docs/reference/install_sp.html index 3dfb3132..50b028b2 100644 --- a/docs/reference/install_sp.html +++ b/docs/reference/install_sp.html @@ -7,7 +7,7 @@ fistools - 1.2.19 + 1.2.20