Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/cran/FedData
12 May 2025, 03:24:35 UTC
  • Code
  • Branches (41)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    • refs/tags/1.0
    • refs/tags/1.1.0
    • refs/tags/2.0.0
    • refs/tags/2.0.1
    • refs/tags/2.0.10
    • refs/tags/2.0.2
    • refs/tags/2.0.3
    • refs/tags/2.0.4
    • refs/tags/2.0.5
    • refs/tags/2.0.6
    • refs/tags/2.0.7
    • refs/tags/2.0.8
    • refs/tags/2.0.9
    • refs/tags/2.2.0
    • refs/tags/2.3.0
    • refs/tags/2.3.1
    • refs/tags/2.3.2
    • refs/tags/2.3.5
    • refs/tags/2.4.0
    • refs/tags/2.4.5
    • refs/tags/2.4.6
    • refs/tags/2.4.7
    • refs/tags/2.5.0
    • refs/tags/2.5.1
    • refs/tags/2.5.2
    • refs/tags/2.5.3
    • refs/tags/2.5.4
    • refs/tags/2.5.5
    • refs/tags/2.5.6
    • refs/tags/2.5.7
    • refs/tags/3.0.0
    • refs/tags/3.0.1
    • refs/tags/3.0.2
    • refs/tags/3.0.3
    • refs/tags/3.0.4
    • refs/tags/4.0.0
    • refs/tags/4.0.1
    • refs/tags/4.1.0
    • refs/tags/4.2.0
    • refs/tags/4.3.0
    No releases to show
  • c2ec0da
  • /
  • R
  • /
  • UTILITY_FUNCTIONS.R
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:8a47869ec34dc3f001121f069a7f2d2b65118183
origin badgedirectory badge Iframe embedding
swh:1:dir:257fc1a5e7fb6386363bb2616e02893ac18a0f60
origin badgerevision badge
swh:1:rev:0ef07e962c155d2148c943f84020e71615df8485
origin badgesnapshot badge
swh:1:snp:d6fd22c94afe698a333c0af98f5c265e1ea5e20f
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 0ef07e962c155d2148c943f84020e71615df8485 authored by R. Kyle Bocinsky on 09 August 2018, 03:10:03 UTC
version 2.5.5
Tip revision: 0ef07e9
UTILITY_FUNCTIONS.R
# Make CRAN check not complain about "." and package data
if (getRversion() >= "2.15.1") utils::globalVariables(c(".",
                                                        "element",
                                                        "nlcd_tiles",
                                                        "nlcd_landcover_pam",
                                                        "nlcd_canopy_pam",
                                                        "nlcd_impervious_pam",
                                                        "daymet_tiles"))

#' Install and load a package.
#'
#'This is a convenience function that checks whether a package is installed, and if not, installs it.
#'
#' @param x A character string representing the name of a package.
#' @export
#' @keywords internal
pkg_test <- function(x) {
    if (grepl("/", x)) {
        pkgName <- basename(x)
    } else {
        pkgName <- x
    }
    if (!suppressWarnings(require(pkgName, character.only = TRUE))) {
        if (grepl("/", x)) {
            suppressWarnings(devtools::install_github(x))
        } else {
            utils::install.packages(x, dependencies = TRUE, repos = "http://cran.rstudio.com")
        }
    }
    if (!suppressWarnings(require(pkgName, character.only = TRUE))) 
        stop("Package not found")
}

#'Get the rightmost 'n' characters of a character string.
#'
#' @param x A character string.
#' @param n The number of characters to retrieve.
#' @return A character string.
#' @export
#' @keywords internal
substr_right <- function(x, n) {
    substr(x, nchar(x) - n + 1, nchar(x))
}

#'Turn an extent object into a polygon
#'
#' @param x An \code{\link{extent}} object, or an object from which an extent object can be retrieved.
#' @param proj4string A PROJ.4 formatted string defining the required projection. If NULL, 
#' the function will attempt to get the projection from x using \code{\link{projection}}
#' @return A SpatialPolygons object.
#' @export
#' @keywords internal
polygon_from_extent <- function(x, proj4string = NULL) {
    if (is.null(proj4string)) {
        proj4string <- raster::projection(x)
    }
    
    if (class(x) != "extent") {
        x <- raster::extent(x)
    }
    
    extent.matrix <- rbind(c(x@xmin, x@ymin), c(x@xmin, x@ymax), c(x@xmax, x@ymax), c(x@xmax, x@ymin), c(x@xmin, x@ymin))  # clockwise, 5 points to close it
    extent.SP <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(extent.matrix)), "extent")), proj4string = sp::CRS(proj4string))
    return(extent.SP)
}

#'Turn a SpatialPolygons object into a SpatialPolygonsDataFrame.
#'
#' @param x An SpatialPolygons object.
#' @return A SpatialPolygonsDataFrame object.
#' @export
#' @keywords internal
spdf_from_polygon <- function(x) {
    IDs <- sapply((methods::slot(x, "polygons")), function(x) {
        methods::slot(x, "ID")
    })
    df <- data.frame(rep(0, length(IDs)), row.names = IDs)
    x <- sp::SpatialPolygonsDataFrame(x, df)
    return(x)
}

#'Get a logical vector of which elements in a vector are sequentially duplicated.
#'
#' @param x An vector of any type, or, if \code{rows}, a matrix.
#' @param rows Is x a matrix?
#' @return A logical vector of the same length as x.
#' @export
#' @keywords internal
sequential_duplicated <- function(x, rows = F) {
    if (!rows) {
        duplicates <- c(FALSE, unlist(lapply(1:(length(x) - 1), function(i) {
            duplicated(x[i:(i + 1)])[2]
        })))
    } else {
        duplicates <- c(FALSE, unlist(lapply(1:(nrow(x) - 1), function(i) {
            duplicated(x[i:(i + 1), ])[2]
        })))
    }
    return(duplicates)
}

#'Unwraps a matrix and only keep the first n elements.
#'
#'A function that unwraps a matrix and only keeps the first n elements
#' n can be either a constant (in which case it will be repeated), or a vector
#' @param mat A matrix
#' @param n A numeric vector
#' @return A logical vector of the same length as x
#' @export
#' @keywords internal
unwrap_rows <- function(mat, n) {
    n <- rep_len(n, nrow(mat))
    i <- 0
    out <- lapply(1:nrow(mat), function(i) {
        return(mat[i, 1:n[i]])
    })
    return(as.numeric(do.call(c, out)))
}


#' Use curl to download a file.
#'
#' This function makes it easy to implement timestamping and no-clobber of files.
#'
#' If both \code{timestamping} and \code{nc} are TRUE, nc behavior trumps timestamping.
#'
#' @param url The location of a file.
#' @param destdir Where the file should be downloaded to.
#' @param timestamping Should only newer files be downloaded?
#' @param nc Should files of the same type not be clobbered?
#' @param verbose Should cURL output be shown?
#' @param progress Should a progress bar be shown with cURL output?
#' @return A character string of the file path to the downloaded file.
#' @export
#' @keywords internal
download_data <- function(url, destdir = getwd(), timestamping = T, nc = F, verbose = F, progress = F) {
    
    destdir <- normalizePath(paste0(destdir,"/."))
    destfile <- paste0(destdir, "/", basename(url))
    temp.file <- paste0(tempdir(), "/", basename(url))
    
    if (nc & file.exists(destfile)){
      message("Local file exists. Returning.")
      return(destfile)
    } else if (timestamping & file.exists(destfile)) {
        message("Downloading file (if necessary): ", url)
        opts <- list(verbose = verbose, noprogress = !progress, fresh_connect = TRUE, ftp_use_epsv = FALSE, forbid_reuse = TRUE, 
            timecondition = TRUE, timevalue = base::file.info(destfile)$mtime)
        hand <- curl::new_handle()
        curl::handle_setopt(hand, .list = opts)
        tryCatch(status <- curl::curl_fetch_disk(url, path = temp.file, handle = hand),
                 error = function(e) {
          message("Download of ", 
            url, " failed. Reverting to already cached file.")
          return(destfile)
          })
        
        if (file.info(temp.file)$size > 0) {
            file.copy(temp.file, destfile, overwrite = T)
        }
        return(destfile)
    } else {
        message("Downloading file: ", url)
        opts <- list(verbose = verbose,
                     noprogress = !progress,
                     fresh_connect = TRUE,
                     ftp_use_epsv = FALSE,
                     forbid_reuse = TRUE)
        hand <- curl::new_handle()
        curl::handle_setopt(hand, .list = opts)
        tryCatch(status <- curl::curl_fetch_disk(url,
                                                 path = destfile,
                                                 handle = hand),
                 error = function(e) stop("Download of ", url, " failed!"))
        return(destfile)
    }
    return(destfile)
}

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API