Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Earth Sciences
startR
Commits
64199019
Commit
64199019
authored
Sep 21, 2017
by
Nicolau Manubens Gil
Browse files
Small progress.
parent
a99c297f
Changes
1
Hide whitespace changes
Inline
Side-by-side
R/XlsPlugin.R
View file @
64199019
...
...
@@ -29,7 +29,7 @@ XlsDimReader <- function(file_path = NULL, file_object = NULL,
#####
#####
vars_in_file
<-
readxl
::
excel_sheets
vars_in_file
<-
c
(
readxl
::
excel_sheets
,
'col_names'
)
#####
if
(
any
(
c
(
'var'
,
'variable'
)
%in%
names
(
inner_indices
)))
{
vars_to_read
<-
inner_indices
[[
which
(
names
(
inner_indices
)
%in%
c
(
'var'
,
'variable'
))[
1
]]]
...
...
@@ -76,13 +76,17 @@ XlsDimReader <- function(file_path = NULL, file_object = NULL,
vars_to_read
<-
SelectorChecker
(
vars_to_read
,
vars_in_file
,
return_indices
=
FALSE
)
#####
rows
<-
read_xls
(
file_to_read
,
vars_to_read
[
1
],
cell_limits
(
c
(
1
,
1
),
c
(
1
,
NA
)))
cols
<-
read_xls
(
file_to_read
,
vars_to_read
[
1
],
cell_limits
(
c
(
1
,
1
),
c
(
NA
,
1
)))
rows
<-
max
(
sapply
(
vars_to_read
,
function
(
x
)
{
read_xls
(
file_to_read
,
x
,
cell_limits
(
c
(
1
,
1
),
c
(
1
,
NA
)))
}))
cols
<-
max
(
sapply
(
vars_to_read
,
function
(
x
)
{
read_xls
(
file_to_read
,
x
,
cell_limits
(
c
(
1
,
1
),
c
(
NA
,
1
)))
}))
read_dims
<-
c
(
var
=
length
(
vars_to_read
),
rows
=
length
(
rows
)
,
cols
=
length
(
cols
)
)
rows
=
rows
,
cols
=
cols
)
#####
if
(
any
(
c
(
'var'
,
'variable'
)
%in%
names
(
inner_indices
)))
{
names
(
read_dims
)[
which
(
names
(
read_dims
)
==
'var'
)]
<-
var_tag
...
...
@@ -149,6 +153,9 @@ XlsDataReader <- function(file_path = NULL, file_object = NULL,
return
(
NULL
)
}
# Flag to know whether a variable has been requested (take all dims detected)
# or whether data has been requested (stop if no indices provided for any
# dim).
var_requested
<-
is.null
(
inner_indices
)
drop_var_dim
<-
FALSE
...
...
@@ -235,11 +242,18 @@ XlsDataReader <- function(file_path = NULL, file_object = NULL,
}
if
(
var_requested
)
{
#####
for
var_name
in
var_names
if
(
var_name
==
'col_names'
)
load
the
first
row.
else
result
<-
readxl
::
read_xls
(
file_to_read
,
var_name
,
cell_limits
(
c
(
1
,
1
,
....
),
c
(
NA
,
NA
,
.....
)),
col_names
=
TRUE
)
if
drop_var_dim
drop
if
(
var_name
==
'col_names'
)
{
## TODO: Add support for different col names for each sheet.
## TODO: If col_names specified in ... and == FALSE, stop.
result
<-
readxl
::
read_xls
(
file_to_read
,
1
,
cell_limits
(
c
(
1
,
1
),
c
(
1
,
NA
)),
col_names
=
TRUE
)
}
else
{
result
<-
readxl
::
read_xls
(
file_to_read
,
var_name
,
cell_limits
(
c
(
1
,
1
),
c
(
NA
,
NA
)),
col_names
=
TRUE
)
}
result
<-
array
(
unlist
(
result
,
use.names
=
FALSE
),
dim
=
c
(
var
=
1
,
rows
=
dim
(
result
)[
1
],
cols
=
dim
(
result
)[
2
]))
if
(
drop_var_dim
)
{
dim
(
result
)
<-
dim
(
result
)[
-1
]
}
##result <- easyNCDF::NcToArray(file_to_read, inner_indices, drop_var_dim = drop_var_dim,
## expect_all_indices = FALSE, allow_out_of_range = TRUE)
#####
...
...
@@ -255,8 +269,12 @@ XlsDataReader <- function(file_path = NULL, file_object = NULL,
file_path
)
}
#####
result
<-
easyNCDF
::
NcToArray
(
file_to_read
,
inner_indices
,
drop_var_dim
=
drop_var_dim
,
expect_all_indices
=
TRUE
,
allow_out_of_range
=
TRUE
)
for
var_name
in
var_names
compute
min
and
max
indices
for
each
dimension
#result <- easyNCDF::NcToArray(file_to_read, inner_indices, drop_var_dim = drop_var_dim,
# expect_all_indices = TRUE, allow_out_of_range = TRUE)
subset
taking
only
indices
in
inner
dims
reorder
dims
according
to
inner_indices
#####
}
names
(
dim
(
result
))
<-
sapply
(
names
(
dim
(
result
)),
...
...
Write
Preview
Supports
Markdown
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