Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dataRetrieval
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Water
dataRetrieval
Commits
34403cc8
Commit
34403cc8
authored
9 years ago
by
Laura A DeCicco
Browse files
Options
Downloads
Patches
Plain Diff
More ways to deal with int/site bug.
parent
49bae52d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!153
int bug fix
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
NAMESPACE
+1
-0
1 addition, 0 deletions
NAMESPACE
R/importRDB1.r
+21
-13
21 additions, 13 deletions
R/importRDB1.r
R/importWQP.R
+9
-2
9 additions, 2 deletions
R/importWQP.R
tests/testthat/tests_general.R
+3
-0
3 additions, 0 deletions
tests/testthat/tests_general.R
with
34 additions
and
15 deletions
NAMESPACE
+
1
−
0
View file @
34403cc8
...
...
@@ -43,6 +43,7 @@ importFrom(lubridate,fast_strptime)
importFrom(lubridate,parse_date_time)
importFrom(plyr,rbind.fill.matrix)
importFrom(readr,col_character)
importFrom(readr,col_number)
importFrom(readr,cols)
importFrom(readr,parse_number)
importFrom(readr,problems)
...
...
This diff is collapsed.
Click to expand it.
R/importRDB1.r
+
21
−
13
View file @
34403cc8
...
...
@@ -117,15 +117,6 @@ importRDB1 <- function(obs_url, asDateTime=TRUE, convertType = TRUE, tz=""){
if
(
convertType
){
readr.data
<-
suppressWarnings
(
read_delim
(
doc
,
skip
=
(
meta.rows
+2
),
delim
=
"\t"
,
col_names
=
FALSE
))
badCols
<-
problems
(
readr.data
)
$
col
if
(
length
(
badCols
)
>
0
){
unique.bad.cols
<-
unique
(
badCols
)
readr.data.char
<-
read_delim
(
doc
,
skip
=
(
meta.rows
+2
),
delim
=
"\t"
,
col_names
=
FALSE
,
col_types
=
cols
(
.default
=
"c"
))
readr.data
[,
unique.bad.cols
]
<-
lapply
(
readr.data.char
[,
unique.bad.cols
],
parse_number
)
}
}
else
{
readr.data
<-
read_delim
(
doc
,
skip
=
(
meta.rows
+2
),
delim
=
"\t"
,
col_names
=
FALSE
,
col_types
=
cols
(
.default
=
"c"
))
}
...
...
@@ -133,15 +124,32 @@ importRDB1 <- function(obs_url, asDateTime=TRUE, convertType = TRUE, tz=""){
names
(
readr.data
)
<-
header.names
if
(
"site_no"
%in%
names
(
readr.data
)){
if
(
!
is.integer
(
readr.data
$
site_no
)){
if
(
is.null
(
readr.data.char
)){
if
(
is.integer
(
readr.data
$
site_no
)){
readr.data.char
<-
read_delim
(
doc
,
skip
=
(
meta.rows
+2
),
delim
=
"\t"
,
col_names
=
FALSE
,
col_types
=
cols
(
.default
=
"c"
))
names
(
readr.data.char
)
<-
header.names
readr.data
$
site_no
<-
readr.data.char
$
site_no
}
}
badCols
<-
problems
(
readr.data
)
$
col
if
(
length
(
badCols
)
>
0
){
unique.bad.cols
<-
unique
(
badCols
)
index.col
<-
as.integer
(
gsub
(
"X"
,
""
,
unique.bad.cols
))
if
(
!
(
all
(
header.names
[
index.col
]
%in%
"site_no"
))){
unique.bad.cols
<-
unique.bad.cols
[
!
(
header.names
[
index.col
]
%in%
"site_no"
)]
index.col
<-
as.integer
(
gsub
(
"X"
,
""
,
unique.bad.cols
))
unique.bad.cols.names
<-
header.names
[
index.col
]
if
(
!
exists
(
"readr.data.char"
)){
readr.data.char
<-
read_delim
(
doc
,
skip
=
(
meta.rows
+2
),
delim
=
"\t"
,
col_names
=
FALSE
,
col_types
=
cols
(
.default
=
"c"
))
}
names
(
readr.data.char
)
<-
header.names
readr.data
$
site_no
<-
readr.data.char
$
site_no
readr.data
[,
unique.bad.cols.names
]
<-
lapply
(
readr.data.char
[,
unique.bad.cols
],
parse_number
)
}
}
comment
(
readr.data
)
<-
readr.meta
readr.data
<-
as.data.frame
(
readr.data
)
...
...
This diff is collapsed.
Click to expand it.
R/importWQP.R
+
9
−
2
View file @
34403cc8
...
...
@@ -19,6 +19,7 @@
#' @import stats
#' @importFrom readr read_delim
#' @importFrom readr col_character
#' @importFrom readr col_number
#' @importFrom readr cols
#' @importFrom dplyr mutate_
#' @importFrom dplyr mutate_each_
...
...
@@ -89,7 +90,10 @@ importWQP <- function(obs_url, zip=FALSE, tz=""){
col_types
=
cols
(
`ActivityStartTime/Time`
=
col_character
(),
`ActivityEndTime/Time`
=
col_character
(),
USGSPCode
=
col_character
(),
ResultCommentText
=
col_character
()),
ResultCommentText
=
col_character
(),
`ActivityDepthHeightMeasure/MeasureValue`
=
col_number
(),
`DetectionQuantitationLimitMeasure/MeasureValue`
=
col_number
(),
ResultMeasureValue
=
col_number
()),
quote
=
""
,
delim
=
"\t"
)
unlink
(
doc
)
}
else
{
...
...
@@ -97,7 +101,10 @@ importWQP <- function(obs_url, zip=FALSE, tz=""){
col_types
=
cols
(
`ActivityStartTime/Time`
=
col_character
(),
`ActivityEndTime/Time`
=
col_character
(),
USGSPCode
=
col_character
(),
ResultCommentText
=
col_character
()),
ResultCommentText
=
col_character
(),
`ActivityDepthHeightMeasure/MeasureValue`
=
col_number
(),
`DetectionQuantitationLimitMeasure/MeasureValue`
=
col_number
(),
ResultMeasureValue
=
col_number
()),
quote
=
""
,
delim
=
"\t"
)
}
}
else
{
...
...
This diff is collapsed.
Click to expand it.
tests/testthat/tests_general.R
+
3
−
0
View file @
34403cc8
...
...
@@ -26,6 +26,9 @@ test_that("General NWIS retrievals working", {
"drain_area_va"
,
"obs_count_nu"
),
service
=
"qw"
)
expect_is
(
qwData
$
startDateTime
,
"POSIXct"
)
url
<-
"http://waterservices.usgs.gov/nwis/dv/?Access=0&site=09037500&format=rdb&ParameterCd=00060&StatCd=00003&startDT=1985-10-02&endDT=2012-09-06"
dv
<-
importRDB1
(
url
,
asDateTime
=
FALSE
)
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment