forked from PecanProject/pecan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpriordupe.R
49 lines (43 loc) · 1.98 KB
/
priordupe.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
##' Duplicate existing prior for new pft
##'
##' Creates a new pft that is a duplicate of an existing pft,
##' including relationships with priors and species of the existing pft
##' @title Duplicate PFT
##' @param parent.pft.name
##' @param new.pft.name
##' @param new.pft.definition
##' @return nothing, creates new pft in database as a side-effect
##' @author David LeBauer
##' @exampe \dontrun{
##' priordupe(parent.pft.name = "tempdecid",
##' new.pft.name = "mytempdecid",
##' new.pft.definition = "mytempdecid is a new pft")
##' }
priordupe <- function(parent.pft.name = NULL,
new.pft.name = NULL,
new.pft.definition = NULL){
require(PEcAn.DB)
parent.pft.id <- query.base(paste("select id from pfts where name = ",
parent.pft.name, ";"))
## create new pft
query.base(paste("insert into pfts set definition = ",
newpftdefn, " name = ",
new.pft.name, ";"))
new.pft.id <- query.base(paste("select id from pfts where name =",
new.pft.name,";"))
old.species.id <- query.base(paste("select specie_id from pfts_species where pft_id =",
parent.pft.id, ";"))
new.pfts_species <- c(pft_id = new.pft.id, specie_id = unique(old.species.id))
query.base(paste("insert into pfts_species set pft_id = ",
new.pfts_species$pft_id,
"specie_id = ",
new.pfts_species$specie_id, ";"))
old.priors <- query.base(paste("select prior_id from pfts_priors where pft_id =",
parent.pft.id, ";"))
new.pfts_priors <- c(pft_id = new.pft.id,
prior_id = unique(old.priors))
query.base(paste("insert into pfts_priors set pft_id = ",
new.pfts_priors$pft_id,
"specie_id = ",
new.pfts_priors$priors_id, ";"))
}