Skip to content

Commit

Permalink
Change csv2.reader() to use R's read.csv2() function as announced in #…
Browse files Browse the repository at this point in the history
…195 and discussed in #170 (#196)

* Change csv2.reader() to use R's read.csv2() function as announced in #195 and #170

* Update csv2.reader.R

* Update migrate.project.R
  • Loading branch information
crubb authored and KentonWhite committed Apr 25, 2018
1 parent 8072e51 commit 6a1ced1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
20 changes: 12 additions & 8 deletions R/csv2.reader.R
@@ -1,8 +1,13 @@
#' Read a semicolon separated values (.csv2) file.
#' Read a semicolon separated values (.csv2) file using R's read.csv2().
#'
#' This function will load a data set stored in the CSV2 file format into
#' the specified global variable binding. The default behaviour will soon
#' change to actually use R's read.csv2() function, assuming dec=".", sep=";".
#' This function will load a data set stored in the CSV file format, where
#' the decimal separator is ',' and the field separator is ';', e.g. due to
#' localized exports of dutch, german or swedish data, into the specified
#' global variable binding.
#'
#' Note: Before June 2017, the reader for .csv2 files assumed the field
#' separator to be ';' and the decimal separator to be '.'. Nowadays, R's
#' read.csv2() function is used.
#'
#' @param data.file The name of the data file to be read.
#' @param filename The path to the data set to be loaded.
Expand All @@ -18,7 +23,7 @@
#' @importFrom utils unzip
csv2.reader <- function(data.file, filename, variable.name)
{
warning("csv2.reader's currently does not use R's read.csv2(), but will do so in the near future. (Background: Currently csv2.reader() assumes ';' as a field separator, but still assumes '.' as a decimal separator where a ',' would be expected.)");
warning("In May 2018, the default behaviour of the reader for .csv2 files changed to use R's read.csv2(), where the field separator is assumed to be ';' and the decimal separator to be ','.")

if (grepl('\\.zip$', filename))
{
Expand All @@ -30,8 +35,7 @@ csv2.reader <- function(data.file, filename, variable.name)
}

assign(variable.name,
read.csv(filename,
header = config$data_loading_header,
sep = ';'),
read.csv2(filename,
header = config$data_loading_header),
envir = .TargetEnv)
}
6 changes: 3 additions & 3 deletions R/migrate.project.R
Expand Up @@ -131,9 +131,9 @@ migrate.project <- function()

if (csv2_files_present) {
message(paste("",
"In the near future, the csv2.reader() behaviour will change to actually using",
"R's read.csv2() method, which assumes the decimal separator to be ',' and the",
"field separator to be ';'. Before, the decimal operator was expected to be '.'.",
"In May 2018, the behaviour of the .csv2 file reader changed to use R's read.csv2()",
"function, which assumes the field separator to be ';' and the decimal separator to",
"be ','. Before, the decimal operator in .csv2 files was expected to be '.'.",
"(See https://github.com/johnmyleswhite/ProjectTemplate/issues/170).",
"",
"Please review your code and datafiles.",
Expand Down
14 changes: 10 additions & 4 deletions man/csv2.reader.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-migration.R
Expand Up @@ -195,7 +195,7 @@ test_that('migrating a project with a data/*.csv2 file results in a message to u
expect_warning(suppressMessages(load.project()), "csv2")

# should be a message to say check code and data for .csv2 files
expect_message(migrate.project(), "csv2")
expect_message(migrate.project(), 'csv2')

suppressMessages(load.project())

Expand Down

0 comments on commit 6a1ced1

Please sign in to comment.