Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
citizenair
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vmm
citizenair
Commits
64062625
Commit
64062625
authored
Nov 12, 2018
by
Jan Wijffels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add lubridate failover strategy if time/date is not in correct format
parent
c869fadc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
0 deletions
+34
-0
citizenair/R/read-citizendata.R
+29
-0
citizenair/inst/data-raw/Test.xls
+0
-0
citizenair/inst/data-raw/Test_LeuvenairVMM_v3.xls
+0
-0
citizenair/man/as.data.frame.citizenair_userdata.Rd
+5
-0
No files found.
citizenair/R/read-citizendata.R
View file @
64062625
...
...
@@ -75,6 +75,11 @@ read_citizenair <- function(file = system.file(package = "citizenair", "data-raw
#' x <- read_citizenair(filename)
#' meta <- as.data.frame(x, type = "meta")
#' measurements <- as.data.frame(x, type = "measurements")
#'
#' filename <- system.file(package = "citizenair", "data-raw", "Test_LeuvenairVMM_v3.xls")
#' x <- read_citizenair(filename)
#' meta <- as.data.frame(x, type = "meta")
#' measurements <- as.data.frame(x, type = "measurements")
as.data.frame.citizenair_userdata
<-
function
(
x
,
row.names
,
optional
,
...
,
type
=
c
(
"meta"
,
"measurements"
)){
type
<-
match.arg
(
type
)
if
(
type
==
"meta"
){
...
...
@@ -201,5 +206,29 @@ read_sheet_measurements <- function(file, sheet, sheet_info = read_sheet_info(fi
stop
(
"Datum + Tijd not present in data"
)
}
x
<-
data.table
::
setnames
(
x
,
old
=
colnames
(
x
)[
idx
],
new
=
c
(
"datum"
,
"tijd"
))
if
(
all
(
is.na
(
x
$
datum
))
||
all
(
is.na
(
x
$
tijd
))){
## failover strategy - maybe data is text and not dates ...
suppressWarnings
(
message
<-
capture.output
(
y
<-
readxl
::
read_excel
(
path
=
file
,
sheet
=
sheet
,
range
=
cellranger
::
cell_limits
(
ul
=
c
(
sheet_info
$
data_start
,
sheet_info
$
measurements_columns
[
1
]),
lr
=
c
(
sheet_info
$
data_start
+
sheet_info
$
data_n
-
1
,
sheet_info
$
measurements_columns
[
2
])),
col_names
=
sheet_info
$
measurements_fields
,
guess_max
=
10000
,
col_types
=
c
(
"text"
,
"text"
,
rep
(
"numeric"
,
length
(
sheet_info
$
measurements_fields
)
-
2
))),
type
=
"message"
))
class
(
y
)
<-
c
(
"data.frame"
,
"citizenair_rawdata"
)
idx
<-
match
(
c
(
"datum"
,
"tijd"
),
table
=
tolower
(
colnames
(
y
)))
y
<-
data.table
::
setnames
(
y
,
old
=
colnames
(
y
)[
idx
],
new
=
c
(
"datum"
,
"tijd"
))
## try to fill data based on parsed text
idx
<-
which
(
is.na
(
x
$
datum
))
if
(
length
(
idx
)
>
0
){
x
$
datum
[
idx
]
<-
lubridate
::
parse_date_time
(
y
$
datum
[
idx
],
"d/m/Y"
,
locale
=
"Dutch_Belgium.1252"
,
tz
=
"UTC"
)
}
idx
<-
which
(
is.na
(
x
$
tijd
))
if
(
length
(
idx
)
>
0
){
x
$
tijd
[
idx
]
<-
lubridate
::
parse_date_time
(
y
$
tijd
[
idx
],
"H!:!M:!S"
,
locale
=
"Dutch_Belgium.1252"
,
tz
=
"UTC"
)
}
}
x
}
citizenair/inst/data-raw/Test.xls
0 → 100644
View file @
64062625
File added
citizenair/inst/data-raw/Test_LeuvenairVMM_v3.xls
0 → 100644
View file @
64062625
File added
citizenair/man/as.data.frame.citizenair_userdata.Rd
View file @
64062625
...
...
@@ -33,4 +33,9 @@ filename <- system.file(package = "citizenair", "data-raw", "citizenair-example.
x <- read_citizenair(filename)
meta <- as.data.frame(x, type = "meta")
measurements <- as.data.frame(x, type = "measurements")
filename <- system.file(package = "citizenair", "data-raw", "Test_LeuvenairVMM_v3.xls")
x <- read_citizenair(filename)
meta <- as.data.frame(x, type = "meta")
measurements <- as.data.frame(x, type = "measurements")
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment