Skip to content

Commit e22db19

Browse files
committed
Fill in missing months of plot treatment assignment [minor]
1 parent e25ca1e commit e22db19

File tree

3 files changed

+480
-33
lines changed

3 files changed

+480
-33
lines changed

DataCleaningScripts/update_portal_plots.R

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ update_portal_plots <- function() {
1515
#load plot data
1616
portal_plots = read.csv("SiteandMethods/Portal_plots.csv",stringsAsFactors = FALSE)
1717
# load rodent data
18-
rodentdat = read.csv("Rodents/Portal_rodent.csv",stringsAsFactors = FALSE,as.is=TRUE,na.strings = '')
18+
rodentdat = read.csv("Rodents/Portal_rodent.csv",
19+
stringsAsFactors = FALSE,as.is=TRUE,na.strings = '')
1920

2021
# define current plot treatments
2122

@@ -24,10 +25,23 @@ update_portal_plots <- function() {
2425
exclosures = c(2,3,8,15,19,20,21,22)
2526

2627
# proceed only if rodentdat has more recent data than plot data
27-
#find new rows
28-
newrows=which(paste(rodentdat$year,rodentdat$month) %in% paste(portal_plots$year,portal_plots$month)
28+
# find new rows
29+
newrows=which(paste(rodentdat$year,rodentdat$month) %in%
30+
paste(portal_plots$year,portal_plots$month)
2931
==FALSE)
30-
newdat = unique(na.omit(rodentdat[newrows,c(2,4)]))
32+
33+
if (length(newrows)>0) {
34+
35+
latest <- unique(na.omit(rodentdat[newrows,c(2,4)])) %>%
36+
mutate(date = as.Date(paste(year,month,"1",sep="-")))
37+
current <- tail(portal_plots[,c(1,2)],1) %>%
38+
mutate(date = as.Date(paste(year,month,"1",sep="-")))
39+
newdat <- data.frame(date = as.Date(current$date:max(latest$date))) %>%
40+
mutate(year = lubridate::year(date),
41+
month = lubridate::month(date)) %>%
42+
select(-date) %>%
43+
unique() %>%
44+
anti_join(current[,1:2], by = join_by(year, month))
3145

3246
if (nrow(newdat)>0) {
3347

@@ -36,13 +50,14 @@ update_portal_plots <- function() {
3650

3751
newplots$treatment = NA
3852

39-
newplots = newplots %>% mutate(treatment = ifelse((plot %in% removals),
40-
"removal", treatment)) %>%
53+
newplots = newplots %>%
54+
mutate(treatment = ifelse((plot %in% removals),"removal", treatment)) %>%
4155
mutate(treatment = ifelse((plot %in% exclosures),"exclosure", treatment)) %>%
4256
mutate(treatment = ifelse((plot %in% controls),"control", treatment))
4357

44-
portal_plots = bind_rows(portal_plots,newplots)
45-
}
58+
portal_plots = bind_rows(portal_plots,newplots) %>% arrange(year,month,plot)
59+
60+
}}
4661

4762
return(portal_plots)
4863
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Build Status](https://github.com/weecology/PortalData/actions/workflows/main.yml/badge.svg)](https://github.com/weecology/PortalData/actions/workflows/main.yml)
55
[![License](http://i.creativecommons.org/p/zero/1.0/88x31.png)](https://raw.githubusercontent.com/weecology/PortalData/main/LICENSE)
66
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1215988.svg)](https://doi.org/10.5281/zenodo.1215988)
7-
[![NSF-1929730](https://img.shields.io/badge/NSF-1929730-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1929730)
7+
[![NSF-2430620](https://img.shields.io/badge/NSF-2430620-blue.svg)](https://www.nsf.gov/awardsearch/show-award?AWD_ID=2430620)
88
<!-- badges: end -->
99

1010
Official Repo of the Portal Project Data

0 commit comments

Comments
 (0)