Skip to content

Commit e6d5235

Browse files
committed
Add dex
1 parent 7b4df17 commit e6d5235

File tree

19 files changed

+161
-35
lines changed

19 files changed

+161
-35
lines changed

CRAN-RELEASE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This package was submitted to CRAN on 2021-06-09.
2+
Once it is accepted, delete this file and tag the release (commit c39aa1c).

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ License: GPL-3
2626
Language: en-US
2727
Encoding: UTF-8
2828
RoxygenNote: 7.1.1
29+
LazyData: true

NAMESPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export(iso)
55
export(wiDB_sites)
66
export(wiDB_data)
77
export(wiDB_values)
8+
export(dex)
89
importFrom(httr, GET, content, user_agent)
910
importFrom(jsonlite, fromJSON)
1011
importFrom(doParallel, registerDoParallel, stopImplicitCluster)
@@ -14,4 +15,4 @@ importFrom(R2WinBUGS, monitor)
1415
importFrom(stats, sd, var)
1516
importFrom(graphics, abline, lines, par, points)
1617
importFrom(abind, abind)
17-
importFrom(utils, read.csv, unzip)
18+
importFrom(utils, read.csv, unzip, data)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# isoWater news
22

33
## isoWater 1.0.1.9000
4+
* Add dex function
5+
* Bug and spelling fixes
46

57
## isoWater 1.0.1
68
* Bug fixes

R/constructors.R

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ iso = function(H, O, Hsd, Osd, HOc = 0){
1818
#####
1919

2020
mwl = function(HO, plot = TRUE){
21-
if(class(HO)[1] != "data.frame"){
21+
if(!inherits(HO, "data.frame")){
2222
stop("HO must be a data.frame")
2323
}
2424
if(!is.numeric(HO[,1]) | !is.numeric(HO[,2])){
@@ -69,3 +69,41 @@ mwl = function(HO, plot = TRUE){
6969
class(mwl) = "mwl"
7070
return(mwl)
7171
}
72+
73+
#####
74+
#--- deuterium excess ----
75+
#calculate dex for one or more samples
76+
#####
77+
78+
dex = function(HO, form = "dex", MWL = NULL){
79+
if(!inherits(HO, "data.frame")){
80+
stop("HO must be a data.frame")
81+
}
82+
if(!is.numeric(HO[,1]) | !is.numeric(HO[,2])){
83+
stop("Non-numeric values in HO")
84+
}
85+
86+
if(is.null(MWL)){
87+
data("GMWL", envir = environment())
88+
GMWL = GMWL
89+
MWL = GMWL
90+
}
91+
92+
if(!is.numeric(MWL) | length(MWL) < 2){
93+
stop("MWL must be mwl object or numeric vector with slope, intercept")
94+
}
95+
96+
if(!(form %in% c("dex", "lcex", "both"))){
97+
stop("form must be dex, lcex, or both")
98+
}
99+
100+
if(form %in% c("dex", "both")){
101+
HO$dex = HO[,1] - 8 * HO[,2]
102+
}
103+
104+
if(form %in% c("lcex", "both")){
105+
HO$lcex = HO[,1] - MWL[1] * HO[,2] - MWL[2]
106+
}
107+
108+
return(HO)
109+
}

R/watercomp.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44

55
#takes values of observed water (type 'iso'), MWL (see below), hypothesized EL slope value
66
#and number of parameter draws
7-
mwlSource = function(obs, MWL=c(8.01, 9.57, -8.096, 2564532.2, 5.76, 80672),
8-
slope, stype = 1, ngens=1e4, ncores = 1){
7+
mwlSource = function(obs, MWL = NULL, slope, stype = 1, ngens=1e4, ncores = 1){
98

9+
if(is.null(MWL)){
10+
data("GMWL", envir = environment())
11+
GMWL = GMWL
12+
MWL = GMWL
13+
}
14+
1015
if(MWL[6] == 80672 & stype == 2){
1116
warning("Using stype=2 and GMWL is inappropriate for most applications; see man")
1217
}
1318

14-
if(length(class(obs)) < 2 | class(obs)[2] != "iso"){
19+
if(!inherits(obs, "iso")){
1520
warning("Expecting iso object for obs, this argument may be formatted incorrectly")
1621
}
1722
if(!(stype %in% c(1, 2))){
@@ -101,7 +106,7 @@ mwlSource = function(obs, MWL=c(8.01, 9.57, -8.096, 2564532.2, 5.76, 80672),
101106
mixSource = function(obs, sources, slope, prior=rep(1,nrow(sources)),
102107
shp=1, ngens=1e5, ncores = 1){
103108

104-
if(length(class(obs)) < 2 | class(obs)[2] != "iso"){
109+
if(!inherits(obs, "iso")){
105110
warning("Expecting iso object for obs, this argument may be
106111
formatted incorrectly")
107112
}
@@ -118,7 +123,7 @@ mixSource = function(obs, sources, slope, prior=rep(1,nrow(sources)),
118123
obs.vcov[2 + (i - 1) * 2, 2] = obs[i, 4] ^ 2
119124
}
120125

121-
if(length(class(sources)) < 2 | class(sources)[2] != "iso"){
126+
if(!inherits(sources, "iso")){
122127
warning("Expecting iso object for sources, this argument may be
123128
formatted incorrectly")
124129
}

R/wiDBfunctions.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,45 @@ wiDB_validate = function(minLat, maxLat, minLong, maxLong, minElev, maxElev,
77
qStr = ""
88

99
if(!is.null(minLat)){
10-
if(class(minLat) != "numeric"){stop("minLat must be numeric")}
10+
if(!inherits(minLat, "numeric")){stop("minLat must be numeric")}
1111
qStr = paste0(qStr, "&minLat=", minLat)
1212
}
1313
if(!is.null(maxLat)){
14-
if(class(maxLat) != "numeric"){stop("maxLat must be numeric")}
14+
if(!inherits(maxLat, "numeric")){stop("maxLat must be numeric")}
1515
qStr = paste0(qStr, "&maxLat=", maxLat)
1616
}
1717
if(!is.null(minLong)){
18-
if(class(minLong) != "numeric"){stop("minLong must be numeric")}
18+
if(!inherits(minLong, "numeric")){stop("minLong must be numeric")}
1919
qStr = paste0(qStr, "&minLong=", minLong)
2020
}
2121
if(!is.null(maxLong)){
22-
if(class(maxLong) != "numeric"){stop("maxLong must be numeric")}
22+
if(!inherits(maxLong, "numeric")){stop("maxLong must be numeric")}
2323
qStr = paste0(qStr, "&maxLong=", maxLong)
2424
}
2525
if(!is.null(minElev)){
26-
if(class(minElev) != "numeric"){stop("minElev must be numeric")}
26+
if(!inherits(minElev, "numeric")){stop("minElev must be numeric")}
2727
qStr = paste0(qStr, "&minElev=", minElev)
2828
}
2929
if(!is.null(maxElev)){
30-
if(class(maxElev) != "numeric"){stop("maxElev must be numeric")}
30+
if(!inherits(maxElev, "numeric")){stop("maxElev must be numeric")}
3131
qStr = paste0(qStr, "&maxElev=", maxElev)
3232
}
3333
if(!is.null(minDate)){
34-
if(class(minDate) != "character"){stop("minDate must be string")}
34+
if(!inherits(minDate, "character")){stop("minDate must be string")}
3535
td = c(as.numeric(substr(minDate, 1, 4)), as.numeric(substr(minDate, 6, 7)),
3636
as.numeric(substr(minDate, 9, 10)))
3737
if(NA %in% td){stop("minDate format must be YYYY-MM-DD")}
3838
qStr = paste0(qStr, "&minDate=", minDate)
3939
}
4040
if(!is.null(maxDate)){
41-
if(class(maxDate) != "character"){stop("maxDate must be string")}
41+
if(!inherits(maxDate, "character")){stop("maxDate must be string")}
4242
td = c(as.numeric(substr(maxDate, 1, 4)), as.numeric(substr(maxDate, 6, 7)),
4343
as.numeric(substr(maxDate, 9, 10)))
4444
if(NA %in% td){stop("maxDate format must be YYYY-MM-DD")}
4545
qStr = paste0(qStr, "&maxDate=", maxDate)
4646
}
4747
if(!is.null(countries)){
48-
if(class(countries) != "character"){stop("countries must be string")}
48+
if(!inherits(countries, "character")){stop("countries must be string")}
4949
countries = gsub(" ", "", countries)
5050
countries = gsub(" ", "", countries)
5151
if(length(countries > 1)){
@@ -54,7 +54,7 @@ wiDB_validate = function(minLat, maxLat, minLong, maxLong, minElev, maxElev,
5454
qStr = paste0(qStr, "&countries=", countries)
5555
}
5656
if(!is.null(states)){
57-
if(class(states) != "character"){stop("states must be string")}
57+
if(!inherits(states, "character")){stop("states must be string")}
5858
states = gsub(" ", "", states)
5959
states = gsub(" ", "", states)
6060
if(length(states > 1)){
@@ -63,7 +63,7 @@ wiDB_validate = function(minLat, maxLat, minLong, maxLong, minElev, maxElev,
6363
qStr = paste0(qStr, "&states=", states)
6464
}
6565
if(!is.null(types)){
66-
if(class(types) != "character"){stop("types must be string")}
66+
if(!inherits(types, "character")){stop("types must be string")}
6767
types = gsub(" ", "", types)
6868
types = gsub(" ", "", types)
6969
if(length(types > 1)){
@@ -72,7 +72,7 @@ wiDB_validate = function(minLat, maxLat, minLong, maxLong, minElev, maxElev,
7272
qStr = paste0(qStr, "&types=", types)
7373
}
7474
if(!is.null(projects)){
75-
if(class(projects) != "character"){stop("projects must be string")}
75+
if(!inherits(projects, "character")){stop("projects must be string")}
7676
projects = gsub(" ", "", projects)
7777
projects = gsub(" ", "", projects)
7878
if(length(projects > 1)){
@@ -148,7 +148,7 @@ wiDB_data = function(minLat = NULL, maxLat = NULL, minLong = NULL, maxLong = NUL
148148
if(!dir.exists(tmpdir)){stop("Unable to create directory")}
149149
}
150150

151-
if(class(clean) != "logical"){stop("clean must be TRUE/FALSE")}
151+
if(!inherits(clean, "logical")){stop("clean must be TRUE/FALSE")}
152152

153153
flist = c("Site_ID", "Site_Name", "Latitude", "Longitude", "Elevation",
154154
"Sample_ID", "Type", "Start_Date", "Start_Time_Zone",
@@ -158,7 +158,7 @@ wiDB_data = function(minLat = NULL, maxLat = NULL, minLong = NULL, maxLong = NUL
158158
"Project_ID")
159159

160160
if(!is.null(fields)){
161-
if(class(fields) != "character"){stop("fields must be a string")}
161+
if(!inherits(fields, "character")){stop("fields must be a string")}
162162
fields = gsub(" ", "", fields)
163163
fields = gsub(" ", "", fields)
164164
fels = strsplit(fields, ",")

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ Putman, A. L., & Bowen, G. J. (2019) A global database of the stable isotopic ra
1616

1717
<!-- badges: start -->
1818
[![Build status](https://github.com/SPATIAL-Lab/isoWater/actions/workflows/r.yml/badge.svg)](https://github.com/SPATIAL-Lab/isoWater/actions)
19-
[![codecov](https://codecov.io/gh/SPATIAL-Lab/isoWater/branch/master/graph/badge.svg)](https://codecov.io/gh/SPATIAL-Lab/isoWater)
19+
[![codecov](https://codecov.io/gh/SPATIAL-Lab/isoWater/branch/master/graph/badge.svg)](https://app.codecov.io/gh/SPATIAL-Lab/isoWater)
2020
<!-- badges: end -->

data-raw/prepData.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ mixModel = "model{
5353
}"
5454

5555
use_data(mwlModel, mixModel, internal = TRUE, overwrite = TRUE)
56+
57+
GMWL = c(8.01, 9.57, -8.096, 2564532.2, 5.76, 80672)
58+
use_data(GMWL, overwrite = TRUE)

data/GMWL.rda

138 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)