Skip to content

Commit eaddbae

Browse files
committed
vignettes
1 parent 21dc0b9 commit eaddbae

11 files changed

Lines changed: 103 additions & 92 deletions

‎.Rbuildignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
^Meta$
2+
^doc$
13
^.*\.Rproj$
24
^\.Rproj\.user$
35
^\.httr-oauth$

‎DESCRIPTION‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ Imports:
3131
rgdal,
3232
rgeos,
3333
spatstat,
34-
ENMeval
34+
ENMeval,
35+
spThin
3536
VignetteBuilder: knitr

‎R/check.R‎

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#' @param rmm a range model metadata list
1010
#' @param cutoff_distance number of allowed different characters to match standardized names
1111
#' @param returnData logical. If FALSE, the functon will return the (possibly) corrected rmm object. If TRUE, the function will return a data.frame containing information on incorrect names.
12+
#' @param interactiveCorrections logical. If TRUE, the user will be prompted to indicate whether the proposed correction should be accepted, thereby modifying the `rmm` object. If FALSE, suggestions will just be printed to the screen and users can edit them manually.
1213
#' @examples
1314
#' rmm<-rmmTemplate() # Make an empty template
1415
#' rmm$dataPrep$biological$taxonomicHarmonization$taxonomy_source<-"The Plant List"
@@ -30,7 +31,10 @@
3031
#' @import utils
3132
#' @export
3233

33-
rmmCheckName <- function(rmm, cutoff_distance = 3, returnData = F ){
34+
rmmCheckName <- function(rmm,
35+
cutoff_distance = 3,
36+
returnData = F,
37+
interactiveCorrections=FALSE ){
3438

3539
list_elements<-utils::capture.output(rmm)
3640
list_elements<-list_elements[grep(pattern = "$",x = list_elements,fixed = T)] #remove elements that aren't field names
@@ -80,31 +84,32 @@ rmmCheckName <- function(rmm, cutoff_distance = 3, returnData = F ){
8084

8185
if(min_dist<=cutoff_distance){
8286

83-
8487
name_check_df$partial_match[i]<-element_i
85-
name_check_df$partial_match_suggestions[i]<-dd_names[which.min(adist(x = element_i,y = dd_names))]
88+
name_check_df$partial_match_suggestions[i]<-
89+
dd_names[which.min(adist(x = element_i,y = dd_names))]
8690

8791
# prompt
8892
cat("\n\n")
89-
cat("\n Element name '",element_i,"' not found in data dictionary", "!\n
90-
Did you mean: '",name_check_df$partial_match_suggestions[i],"'? \n Type 'y' or 'n'." ) # prompt
91-
take <- scan(n = 1, quiet = TRUE, what = 'raw')
93+
cat("\n Element name '",element_i,"' not found in data dictionary", "!\n Did you mean: '",name_check_df$partial_match_suggestions[i],"'? " ) # prompt
94+
if(interactiveCorrections){
95+
cat("Type 'y' or 'n'.")
9296

93-
if (take == 'y' | take == 'Y') {
94-
#rename list element_i to the partial match suggestion
97+
take <- scan(n = 1, quiet = TRUE, what = 'raw')
9598

96-
el_i<-paste("rmm",element_i,sep = "")
97-
bad_name<-unlist(strsplit(el_i,"$",fixed = T))[length(unlist(strsplit(el_i,"$",fixed = T)))]
98-
parent_i<-paste(unlist(strsplit(el_i,"$",fixed = T))[1:length(unlist(strsplit(el_i,"$",fixed = T)))-1],collapse = "$")
99+
if (take == 'y' | take == 'Y') {
100+
#rename list element_i to the partial match suggestion
99101

100-
exp_i<-paste("names(",parent_i,")[",which(names(eval(parse(text = parent_i)))==bad_name),"] <- '",unlist(strsplit(name_check_df$partial_match_suggestions[i],split = "$",fixed = T))[length(unlist(strsplit(name_check_df$partial_match_suggestions[i],split = "$",fixed = T)))],"'",sep = "")
101-
eval(parse(text = exp_i))
102-
name_check_df$corrected_name[i]<-dd_names[which.min(adist(x = element_i,y = dd_names))]
102+
el_i<-paste("rmm",element_i,sep = "")
103+
bad_name<-unlist(strsplit(el_i,"$",fixed = T))[length(unlist(strsplit(el_i,"$",fixed = T)))]
104+
parent_i<-paste(unlist(strsplit(el_i,"$",fixed = T))[1:length(unlist(strsplit(el_i,"$",fixed = T)))-1],collapse = "$")
103105

104-
}
106+
exp_i<-paste("names(",parent_i,")[",which(names(eval(parse(text = parent_i)))==bad_name),"] <- '",unlist(strsplit(name_check_df$partial_match_suggestions[i],split = "$",fixed = T))[length(unlist(strsplit(name_check_df$partial_match_suggestions[i],split = "$",fixed = T)))],"'",sep = "")
107+
eval(parse(text = exp_i))
108+
name_check_df$corrected_name[i]<-dd_names[which.min(adist(x = element_i,y = dd_names))]
105109

110+
}
111+
} # end interactive corrections
106112
#end prompt
107-
108113
}
109114

110115
if(min_dist>cutoff_distance){
@@ -152,8 +157,9 @@ rmmCheckName <- function(rmm, cutoff_distance = 3, returnData = F ){
152157

153158
}#overall fx
154159

155-
}
160+
}
156161

162+
####################################################################
157163
##############################################################
158164
##############################################################
159165

@@ -309,9 +315,9 @@ rmmCheckValue <- function(rmm, cutoff_distance = 3, returnData = F ){
309315

310316
}#end of fx
311317

312-
#############################
313-
314-
#############################
318+
####################################################################
319+
####################################################################
320+
####################################################################
315321

316322
#' @title Check for missing fields
317323
#'
@@ -339,7 +345,7 @@ rmmCheckValue <- function(rmm, cutoff_distance = 3, returnData = F ){
339345
#' @import utils
340346
#' @export
341347

342-
rmmCheckMissingNames<-function(rmm,family=c("obligate")){
348+
rmmCheckMissingNames<-function(rmm,family=c("base")){
343349

344350
list_elements<-capture.output(rmm)
345351
list_elements<-list_elements[grep(pattern = "$",x = list_elements,fixed = T)] #remove elements that aren't field names
@@ -386,7 +392,9 @@ rmmCheckMissingNames<-function(rmm,family=c("obligate")){
386392
}
387393

388394

389-
##################################
395+
####################################################################
396+
####################################################################
397+
####################################################################
390398
#' @title Check an rmm object for empty fields
391399
#'
392400
#' @description Identify empty fields in an rmm object and classify these into obligate and optional fields.
@@ -395,7 +403,7 @@ rmmCheckMissingNames<-function(rmm,family=c("obligate")){
395403
#' See Examples.
396404
#'
397405
#' @param rmm a range model metadata list
398-
#' @param family an rmm family, "apObligate" by default
406+
#' @param family an rmm family, "base" by default
399407
#'
400408
#' @examples
401409
#' #First, make an empty rmm object:
@@ -420,7 +428,7 @@ rmmCheckMissingNames<-function(rmm,family=c("obligate")){
420428
#' @export
421429

422430
#CM: 7/11/18: note that I removed the optional and suggested options as we don't have those any more.
423-
rmmCheckEmpty<-function(rmm, family=c('base','obligate')){
431+
rmmCheckEmpty<-function(rmm, family=c('base')){
424432

425433
list_elements<-capture.output(rmm)
426434
list_elements<-list_elements[grep(pattern = "$",x = list_elements,fixed = T)] #remove elements that aren't field names
@@ -578,7 +586,7 @@ rmmCleanNULLs=function(rmm){
578586
#' @import utils
579587
#' @export
580588

581-
rmmCheckFinalize<-function(rmm,family=c('base','obligate')){
589+
rmmCheckFinalize<-function(rmm,family=c('base')){
582590

583591
names<-rmmCheckName(rmm,returnData = TRUE)
584592

‎R/metadataTemplate.R‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#'
1212
#' @examples
1313
#' rmm1=rmmTemplate()
14-
#' rmm2=rmmTemplate(family=c('base','obligate'))
14+
#' rmm2=rmmTemplate(family=c('base'))
1515
#' str(rmm2)
1616
#'
1717
#' @return a range model metadata list
@@ -28,11 +28,11 @@
2828

2929
rmmTemplate=function(family=NULL){
3030
# for testing
31-
# family=c('base','obligate')
31+
# family=c('base','poop')
3232

3333

3434
# could add a check that valid families are specified
35-
#if(!(family %in% c('apAll','apObligate'))) stop('Specify a correct family.')
35+
if(any(!(family %in% rmmFamilies()))) stop('Specify a correct family. See options with rmmFamilies()')
3636

3737
dd=utils::read.csv(system.file("extdata/dataDictionary.csv",package='rangeModelMetadata'),stringsAsFactors=F)
3838

0 commit comments

Comments
 (0)