Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vital-IT
post-inForm
Commits
ab421232
Commit
ab421232
authored
Oct 15, 2020
by
Robin Engler
Browse files
Add input encoding detection for Windows
parent
4473387a
Changes
3
Hide whitespace changes
Inline
Side-by-side
R/functions.R
View file @
ab421232
...
@@ -355,7 +355,16 @@ guess_file_encoding = function(input_file){
...
@@ -355,7 +355,16 @@ guess_file_encoding = function(input_file){
host_os
=
guess_host_os
()
host_os
=
guess_host_os
()
if
(
host_os
==
'linux'
)
tmp
=
system2
(
"file"
,
args
=
c
(
"-i"
,
paste0
(
"'"
,
input_file
,
"'"
)),
stdout
=
T
)
if
(
host_os
==
'linux'
)
tmp
=
system2
(
"file"
,
args
=
c
(
"-i"
,
paste0
(
"'"
,
input_file
,
"'"
)),
stdout
=
T
)
if
(
host_os
==
'osx'
)
tmp
=
system2
(
"file"
,
args
=
c
(
"-I"
,
paste0
(
"'"
,
input_file
,
"'"
)),
stdout
=
T
)
if
(
host_os
==
'osx'
)
tmp
=
system2
(
"file"
,
args
=
c
(
"-I"
,
paste0
(
"'"
,
input_file
,
"'"
)),
stdout
=
T
)
if
(
host_os
==
'windows'
)
return
(
"native.enc"
)
if
(
host_os
==
'windows'
){
# Determine encoding by looking at the first 2 characters.
file_connection
=
file
(
input_file
,
open
=
'rb'
)
file_start
=
paste
(
readBin
(
con
=
file_connection
,
what
=
'raw'
,
n
=
2
),
collapse
=
''
)
close
(
file_connection
)
# UTF-8 with BOM starts with hexadecimal characters "ef bb". UTF-16 LE with "ff fe".
if
(
file_start
==
'efbb'
)
return
(
"UTF-8-BOM"
)
if
(
file_start
==
'fffe'
)
return
(
"UTF-16LE"
)
return
(
"UTF-8"
)
}
if
(
host_os
==
'unknown'
)
raise_error
(
"Unable to detect host OS."
)
if
(
host_os
==
'unknown'
)
raise_error
(
"Unable to detect host OS."
)
encoding_type
=
sub
(
pattern
=
'^.* charset='
,
replacement
=
''
,
x
=
tmp
)
encoding_type
=
sub
(
pattern
=
'^.* charset='
,
replacement
=
''
,
x
=
tmp
)
...
...
R/load_data.R
View file @
ab421232
...
@@ -177,7 +177,7 @@ read_parameters_file <- function(input_file){
...
@@ -177,7 +177,7 @@ read_parameters_file <- function(input_file){
# Verify that a parameter name has already been defined, and that the parameter value
# Verify that a parameter name has already been defined, and that the parameter value
# line does not contain any ':' character.
# line does not contain any ':' character.
if
(
is.null
(
parameter_name
))
raise_error
(
if
(
is.null
(
parameter_name
))
raise_error
(
msg
=
"The first non-comment line of parameter file
s
must contain a parameter value."
,
msg
=
"The first non-comment line of
a
parameter file must contain a parameter value."
,
file
=
input_file
)
file
=
input_file
)
if
(
grepl
(
pattern
=
':'
,
x
=
line
))
raise_error
(
if
(
grepl
(
pattern
=
':'
,
x
=
line
))
raise_error
(
msg
=
"':' characters are only allowed as parameter delimitors."
,
file
=
input_file
)
msg
=
"':' characters are only allowed as parameter delimitors."
,
file
=
input_file
)
...
...
R/rename_samples.R
View file @
ab421232
...
@@ -40,7 +40,7 @@ rename_samples <- function(samples, session_root_dir){
...
@@ -40,7 +40,7 @@ rename_samples <- function(samples, session_root_dir){
# Case 2: the data must be split into 2.
# Case 2: the data must be split into 2.
}
else
if
(
length
(
new_name
)
==
2
){
}
else
if
(
length
(
new_name
)
==
2
){
# Get imageID values that corresponds to the 2 sub-samples in the original sample.
# Get image
ID values that corresponds to the 2 sub-samples in the original sample.
if
(
file_extension
==
CELL_FILES_EXTENSION
){
if
(
file_extension
==
CELL_FILES_EXTENSION
){
stopifnot
(
'cell_y_position'
%in%
colnames
(
tmp
))
stopifnot
(
'cell_y_position'
%in%
colnames
(
tmp
))
image_id_split
=
split_by_coordinate
(
coordinates
=
tmp
[,
'cell_y_position'
],
image_id_split
=
split_by_coordinate
(
coordinates
=
tmp
[,
'cell_y_position'
],
...
...
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