Commit ab421232 authored by Robin Engler's avatar Robin Engler
Browse files

Add input encoding detection for Windows

parent 4473387a
......@@ -355,7 +355,16 @@ guess_file_encoding = function(input_file){
host_os = guess_host_os()
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 == '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='')
# 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")
if(host_os == 'unknown') raise_error("Unable to detect host OS.")
encoding_type = sub(pattern='^.* charset=', replacement='', x=tmp)
......@@ -177,7 +177,7 @@ read_parameters_file <- function(input_file){
# Verify that a parameter name has already been defined, and that the parameter value
# line does not contain any ':' character.
if(is.null(parameter_name)) raise_error(
msg="The first non-comment line of parameter files must contain a parameter value.",
msg="The first non-comment line of a parameter file must contain a parameter value.",
if(grepl(pattern=':', x=line)) raise_error(
msg="':' characters are only allowed as parameter delimitors.", file=input_file)
......@@ -40,7 +40,7 @@ rename_samples <- function(samples, session_root_dir){
# Case 2: the data must be split into 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){
stopifnot('cell_y_position' %in% colnames(tmp))
image_id_split = split_by_coordinate(coordinates = tmp[,'cell_y_position'],
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment