individual.R
This file should contain your processing workflow and be saved at:
data-raw/individual.R
Create the file using:
::use_data_raw("individual") usethis
Your script should contain:
## code to prepare `individual` dataset goes here
library(dplyr)
source(here::here("R", "geolocate.R"))
# Read in and compile all individual data
<- here::here("data-raw", "wood-survey-data-master")
raw_data_path <- fs::path(raw_data_path, "individual")
individual_path <- fs::dir_ls(individual_path)
individual_paths
# read in all tables into one
<- purrr::map_df(individual_paths,
individual ~readr::read_csv(file = .x,
col_types = readr::cols(.default = "c"))) %>%
::type_convert()
readr
%>%
individual ::write_csv(path = fs::path(raw_data_path, "vst_individuals.csv"))
readr
# Combine NEON data tables
# read in additonal table
<- readr::read_csv(fs::path(raw_data_path,
maptag "vst_mappingandtagging.csv")) %>%
select(-eventID)
<- readr::read_csv(fs::path(raw_data_path,
perplot "vst_perplotperyear.csv")) %>%
select(-eventID)
%<>%
individual left_join(maptag, by = "individualID",
suffix = c("", "_map")) %>%
left_join(perplot, by = "plotID",
suffix = c("", "_ppl")) %>%
::assert(assertr::not_na, stemDistance, stemAzimuth, pointID,
assertr
decimalLongitude, decimalLatitude, plotID)
# ---- Geolocate individuals_functions ----
<- individual %>%
individual ::mutate(stemLat = get_stem_location(decimalLongitude = decimalLongitude,
dplyrdecimalLatitude = decimalLatitude,
stemAzimuth = stemAzimuth,
stemDistance = stemDistance)$lat,
stemLon = get_stem_location(decimalLongitude = decimalLongitude,
decimalLatitude = decimalLatitude,
stemAzimuth = stemAzimuth,
stemDistance = stemDistance)$lon) %>%
::clean_names()
janitor
# create data directory
::dir_create(here::here("data"))
fs
# write out analytic file
::write_csv(individual, here::here("data", "individual.csv")) readr