ropensci / paleobioDB
Showing 3 of 9 files from the diff.

@@ -17,13 +17,13 @@
Loading
17 17
18 18
pbdb_temporal_resolution<- function (data, do.plot=TRUE) {
19 19
  if('eag' %in% colnames(data)) {
20 -
    tr<- list (summary=summary (data$eag - data$lag), 
21 -
               temporal_resolution=(data$eag - data$lag))
20 +
    diff <- .numeric_age(data$eag) - .numeric_age(data$lag)
21 +
    tr<- list (summary=summary (diff), temporal_resolution=diff)
22 22
  }
23 23
  
24 24
  if('early_age' %in% colnames(data)) {
25 -
    tr<- list (summary=summary (data$early_age - data$late_age), 
26 -
               temporal_resolution=(data$early_age - data$late_age))
25 +
    diff <- .numeric_age(data$early_age) - .numeric_age(data$late_age)
26 +
    tr<- list (summary=summary (diff), temporal_resolution=diff)
27 27
    
28 28
  }
29 29
  
@@ -96,56 +96,51 @@
Loading
96 96
97 97
.extract_temporal_range <- function (data, rank) {
98 98
99 -
  if('taxon_rank' %in% colnames(data) && 'genus_name' %in% colnames(data)) {
100 -
    if (rank=="species"){
101 -
      selection<- data [data$matched_rank==rank, ]
102 -
      max_sp<- tapply(selection$early_age, as.character (selection$matched_name), max)
103 -
      min_sp<- tapply(selection$late_age, as.character (selection$matched_name), min)
104 -
    } else if (rank=="genus"){
105 -
      max_sp<- tapply(data$early_age, as.character (data$genus), max)
106 -
      min_sp<- tapply(data$late_age, as.character (data$genus), min)
107 -
    } else if (rank=="family"){
108 -
      max_sp<- tapply(data$early_age, as.character (data$family), max)
109 -
      min_sp<- tapply(data$late_age, as.character (data$family), min)
110 -
    } else if (rank=="order"){
111 -
      max_sp<- tapply(data$early_age, as.character (data$order), max)
112 -
      min_sp<- tapply(data$late_age, as.character (data$order), min)
113 -
    } else if (rank=="class"){
114 -
      max_sp<- tapply(data$early_age, as.character (data$class), max)
115 -
      min_sp<- tapply(data$late_age, as.character (data$class), min)
116 -
    } else if (rank=="phylum"){
117 -
      max_sp<- tapply(data$early_age, as.character (data$phylum), max)
118 -
      min_sp<- tapply(data$late_age, as.character (data$phylum), min)
119 -
    } else {
120 -
      stop(paste("Unknown rank", rank))
121 -
    }
122 -
123 -
  } else if ('rnk' %in% colnames(data) && 'idt' %in% colnames(data)) {
124 -
125 -
    if (rank=="species"){
126 -
      selection<- data [data$mra==3, ]
127 -
      max_sp<- tapply(selection$eag, as.character (selection$mna), max)
128 -
      min_sp<- tapply(selection$lag, as.character (selection$mna), min)
129 -
    } else if (rank=="genus"){
130 -
      max_sp<- tapply(data$eag,as.character (data$gnl), max)
131 -
      min_sp<- tapply(data$lag, as.character (data$gnl), min)
99 +
  if ('taxon_rank' %in% colnames(data)) {
100 +
    long_names <- TRUE
101 +
  } else if ('rnk' %in% colnames(data)) {
102 +
    long_names <- FALSE
103 +
  } else {
104 +
    stop("Cannot extract temporal range from data. Please add show=c('phylo', 'ident') to your pbdb_occurrences query")
105 +
  }
106 +
  
107 +
  early_age_col <- if (long_names) 'early_age' else 'eag'
108 +
  late_age_col <- if (long_names) 'late_age' else 'lag'
109 +
  matched_rank_col <- if (long_names) 'matched_rank' else 'mra'
110 +
  matched_name_col <- if (long_names) 'matched_name' else 'mna'
111 +
  genus_col <- if (long_names) 'genus' else 'gnl'
112 +
  family_col <- if (long_names) 'family' else 'fml'
113 +
  order_col <- if (long_names) 'order' else 'odl'
114 +
  class_col <- if (long_names) 'class' else 'cll'
115 +
  phylum_col <- if (long_names) 'phylum' else 'phl'
116 +
  
117 +
  if (rank=="species"){
118 +
    selection<- data [data[, matched_rank_col]==rank, ]
119 +
    max_sp<- tapply(.numeric_age(selection[, early_age_col]), as.character (selection[, matched_name_col]), max)
120 +
    min_sp<- tapply(.numeric_age(selection[, late_age_col]), as.character (selection[, matched_name_col]), min)
121 +
  } else {
122 +
    
123 +
    early_age = .numeric_age(data[, early_age_col])
124 +
    late_age = .numeric_age(data[, late_age_col])
125 +
    
126 +
    if (rank=="genus"){
127 +
      max_sp<- tapply(early_age, as.character (data[, genus_col]), max)
128 +
      min_sp<- tapply(late_age, as.character (data[, genus_col]), min)
132 129
    } else if (rank=="family"){
133 -
      max_sp<- tapply(data$eag, as.character (data$fml), max)
134 -
      min_sp<- tapply(data$lag, as.character (data$fml), min)
130 +
      max_sp<- tapply(early_age, as.character (data[, family_col]), max)
131 +
      min_sp<- tapply(late_age, as.character (data[, family_col]), min)
135 132
    } else if (rank=="order"){
136 -
      max_sp<- tapply(data$eag, as.character (data$odl), max)
137 -
      min_sp<- tapply(data$lag, as.character (data$odl), min)
133 +
      max_sp<- tapply(early_age, as.character (data[, order_col]), max)
134 +
      min_sp<- tapply(late_age, as.character (data[, order_col]), min)
138 135
    } else if (rank=="class"){
139 -
      max_sp<- tapply(data$eag, as.character (data$cll), max)
140 -
      min_sp<- tapply(data$lag, as.character (data$cll), min)
136 +
      max_sp<- tapply(early_age, as.character (data[, class_col]), max)
137 +
      min_sp<- tapply(late_age, as.character (data[, class_col]), min)
141 138
    } else if (rank=="phylum"){
142 -
      max_sp<- tapply(data$eag, as.character (data$phl), max)
143 -
      min_sp<- tapply(data$lag, as.character (data$phl), min)
139 +
      max_sp<- tapply(early_age, as.character (data[, phylum_col]), max)
140 +
      min_sp<- tapply(late_age, as.character (data[, phylum_col]), min)
144 141
    } else {
145 142
      stop(paste("Unknown rank", rank))
146 143
    }
147 -
  } else {
148 -
    stop("Cannot extract temporal range from data. Please add show=c('phylo', 'ident') to your pbdb_occurrences query")
149 144
  }
150 145
151 146
  temporal_range<- data.frame (max_sp, min_sp)
@@ -155,6 +150,8 @@
Loading
155 150
  return (temporal_range)
156 151
}
157 152
153 +
.numeric_age <- function (f) { as.numeric(as.character(f)) }
154 +
158 155
#' pbdb_richness
159 156
#' 
160 157
#' Plots the number of the interested.

@@ -34,7 +34,7 @@
Loading
34 34
35 35
	if(status != '200'){
36 36
		stop(sprintf('Error in API response. The server returned a status %s, which indicates that 
37 -
			something went wrong with your request. \r\nIn order to debug the problem you may find
37 +
			something went wrong with your request. In order to debug the problem you may find
38 38
			usefull information in the following server response:\r\n%s', status, body))
39 39
	}
40 40

@@ -99,7 +99,7 @@
Loading
99 99
100 100
# Initialize configuration of package API
101 101
.pbdb_setup<-function(){
102 -
	.set_api_base('http://paleobiodb.org/data1.1')
102 +
	.set_api_base('https://paleobiodb.org/data1.1')
103 103
	.pbdb_set_up_endpoints()
104 104
	.package_cache_set('api_format', 'json')
105 105
}
Files Coverage
R 0.00%
Project Totals (8 files) 0.00%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading