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

  • fbf95eb
  • /
  • compute_cover.R
Raw File Download

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
content badge
swh:1:cnt:3d7c71ce9d658c0b4127523a0dbe9784c4d352f8
directory badge
swh:1:dir:fbf95eb0c5587377c9c1598879afdc4f161b28f3

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
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
compute_cover.R
################################################################################
#### Project: Lowland plant migrations alpine soil C loss
#### Title:   Function | Basic formatting of relevee data
#### Author:  Tom Walker (thomas.walker@usys.ethz.ch)
#### Date:    26 May 2021
#### ---------------------------------------------------------------------------

compute_cover <- function(raw_relevees){
  ## Filter for 2017 year only ----
  quad_2017 <- lapply(raw_relevees$quadrats, function(x) x %>% filter(year == 2017))
  rele_2017 <- lapply(raw_relevees$relevees, function(x) x %>% filter(year == 2017))
  ## Match quadrants and relevees to collar data ----
  # quadrants
  quad_matched <- lapply(
    quad_2017, 
    semi_join, 
    y = raw_relevees$collars, 
    by = "grid_id"
  )
  # relevees
  rele_matched <- lapply(
    rele_2017,
    semi_join,
    y = raw_relevees$collars, 
    by = "grid_id"
  )
  ## Quantify bare ground and species cover ----
  # bare ground
  quad_bare <- lapply(
    quad_matched, 
    function(x){
      x %>%
        filter(quadrant_fail != "M") %>%
        group_by(grid_id) %>%
        summarize(total_cover = sum(cover_cm2_bare_soil, na.rm = T)) %>%
        ungroup %>% 
        as.data.frame %>%
        mutate(species = "bare ground")
    }
  )
  # species covers
  rele_sum <- lapply(
    rele_matched, 
    function(x){
      x %>%
        group_by(grid_id, species) %>%
        summarize(total_cover = sum(cover_cm2, na.rm = T)) %>%
        ungroup %>% 
        as.data.frame
    }
  )
  ## Format output ----
  # unlist to data frames
  bare_long <- do.call(rbind, quad_bare)
  rele_long <- do.call(rbind, rele_sum)
  all_long <- rbind(bare_long, rele_long)
  # identify site information
  hilo_id <- substr(all_long$grid_id, 1, 3)
  calanda <- hilo_id %in% c("Cal", "Nes")
  # combine, add site_id, rearrange
  all_out <- all_long %>%
    mutate(site = if_else(calanda, "calanda", "lavey")) %>%
    arrange(grid_id, species) %>%
    remove_rownames
  # return
  return(all_out)
}

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— Content policy— Contact— JavaScript license information— Web API