Skip to content

Commit

Permalink
rename read_csv as fread_csv to avoid conflict with readr
Browse files Browse the repository at this point in the history
- also change read_csv_numer to fread_csv_numer

- also internal function read_mult_csv -> fread_mult_csv

(not sure why these functions are exported; I guess because read_csv is used by qtl2cl)
  • Loading branch information
kbroman committed Aug 24, 2023
1 parent 8343447 commit 83301f7
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 48 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: qtl2
Version: 0.32
Date: 2023-04-21
Version: 0.33-1
Date: 2023-08-24
Title: Quantitative Trait Locus Mapping in Experimental Crosses
Description: Provides a set of tools to perform quantitative
trait locus (QTL) analysis in experimental crosses. It is a
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export(find_markerpos)
export(find_peaks)
export(fit1)
export(founders)
export(fread_csv)
export(fread_csv_numer)
export(genoprob_to_alleleprob)
export(genoprob_to_snpprob)
export(get_common_ids)
Expand Down Expand Up @@ -147,8 +149,6 @@ export(pull_genoprobpos)
export(pull_markers)
export(qtl2version)
export(read_cross2)
export(read_csv)
export(read_csv_numer)
export(read_pheno)
export(recode_snps)
export(reduce_map_gaps)
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## qtl2 0.33-1 (2023-08-24)

### Major changes

- Changed `read_csv()` to `fread_csv()` to avoid conflict with
`readr::read_csv()`. (Issue #223)

- Similarly, changed `read_csv_numer()` to `fread_csv_numer()`.


## qtl2 0.32 (2023-04-21)

### Major changes
Expand Down
6 changes: 3 additions & 3 deletions R/read_csv.R → R/fread_csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
#'
#' The first column is taken to be a set of row names
#'
#' @seealso [read_csv_numer()]
#' @seealso [fread_csv_numer()]
#'
#' @importFrom data.table fread
#' @export
#'
#' @examples
#' \dontrun{mydata <- read_csv("myfile.csv", transpose=TRUE)}
read_csv <-
#' \dontrun{mydata <- fread_csv("myfile.csv", transpose=TRUE)}
fread_csv <-
function(filename, sep=",", na.strings=c("NA", "-"), comment.char="#", transpose=FALSE,
rownames_included=TRUE)
{
Expand Down
6 changes: 3 additions & 3 deletions R/read_csv_numer.R → R/fread_csv_numer.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
#'
#' The first column is taken to be a set of row names
#'
#' @seealso [read_csv()]
#' @seealso [fread_csv()]
#'
#' @importFrom data.table fread
#' @export
#'
#' @examples
#' \dontrun{mydata <- read_csv_numer("myfile.csv", transpose=TRUE)}
read_csv_numer <-
#' \dontrun{mydata <- fread_csv_numer("myfile.csv", transpose=TRUE)}
fread_csv_numer <-
function(filename, sep=",", na.strings=c("NA", "-"), comment.char="#", transpose=FALSE,
rownames_included=TRUE)
{
Expand Down
32 changes: 16 additions & 16 deletions R/read_cross2.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ function(file, quiet=TRUE)
stop_if_no_file(filename)

# read file
sheet <- read_csv(filename, na.strings=control$na.strings, sep=control$sep,
comment.char=control$comment.char, transpose=tr,
rownames_included=TRUE)
sheet <- fread_csv(filename, na.strings=control$na.strings, sep=control$sep,
comment.char=control$comment.char, transpose=tr,
rownames_included=TRUE)
}
else { # vector of files
# add dir to paths
Expand All @@ -145,15 +145,15 @@ function(file, quiet=TRUE)
sheet <- NULL
for(filename in filenames)
sheet <- rbind(sheet,
read_csv(filename, na.strings=control$na.strings,
sep=control$sep, comment.char=control$comment.char,
transpose=tr, rownames_included=TRUE))
fread_csv(filename, na.strings=control$na.strings,
sep=control$sep, comment.char=control$comment.char,
transpose=tr, rownames_included=TRUE))
}
else {
# read all of the files and cbind(), matching on row names
sheet <- read_mult_csv(filenames, na.strings=control$na.strings,
sep=control$sep, comment.char=control$comment.char,
transpose=tr)
sheet <- fread_mult_csv(filenames, na.strings=control$na.strings,
sep=control$sep, comment.char=control$comment.char,
transpose=tr)
}
}
if(length(unique(colnames(sheet))) != ncol(sheet))
Expand Down Expand Up @@ -487,8 +487,8 @@ function(sex_control, covar, sep, comment.char, dir, quiet=TRUE)
if(!quiet) message(" - reading sex")
file <- file.path(dir, sex_control$file)
stop_if_no_file(file)
sex <- read_csv(file, sep=sep, na.strings=NULL, comment.char=comment.char,
rownames_included=TRUE)
sex <- fread_csv(file, sep=sep, na.strings=NULL, comment.char=comment.char,
rownames_included=TRUE)
}
else return(NULL)

Expand Down Expand Up @@ -556,7 +556,7 @@ function(cross_info_control, covar, sep, comment.char, dir, quiet=TRUE)

file <- file.path(dir, cross_info_control$file)
stop_if_no_file(file)
cross_info <- read_csv(file, sep=sep, comment.char=comment.char, rownames_included=TRUE)
cross_info <- fread_csv(file, sep=sep, comment.char=comment.char, rownames_included=TRUE)

if(any(is.na(cross_info)))
stop(sum(is.na(cross_info)), " missing values in cross_info (cross_info can't be missing.")
Expand Down Expand Up @@ -626,14 +626,14 @@ function(filename)


# read multiple CSV files and cbind results
read_mult_csv <-
fread_mult_csv <-
function(filenames, sep=",", na.strings=c("NA", "-"), comment.char="#", transpose=FALSE)
{
result <- NULL
for(file in filenames) {
this <- read_csv(file, sep=sep, na.strings=na.strings,
comment.char=comment.char, transpose=transpose,
rownames_included=TRUE)
this <- fread_csv(file, sep=sep, na.strings=na.strings,
comment.char=comment.char, transpose=transpose,
rownames_included=TRUE)

if(is.null(result)) result <- this
else result <- cbind_expand(result, this)
Expand Down
8 changes: 4 additions & 4 deletions R/read_pheno.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ read_pheno <-
# read file
stop_if_no_file(file)
if(!quiet) message(" - Reading ", basename(file))
pheno <- read_csv_numer(file, sep=sep, na.strings=na.strings,
comment.char=comment.char, transpose=transpose)
pheno <- fread_csv_numer(file, sep=sep, na.strings=na.strings,
comment.char=comment.char, transpose=transpose)
pheno <- as.matrix(pheno)

# read phenocovarfile
Expand Down Expand Up @@ -150,6 +150,6 @@ read_phenocovar <-
# read file
stop_if_no_file(file)
if(!quiet) message(" - Reading ", basename(file))
read_csv(file, sep=sep, na.strings=na.strings,
comment.char=comment.char, transpose=FALSE)
fread_csv(file, sep=sep, na.strings=na.strings,
comment.char=comment.char, transpose=FALSE)
}
12 changes: 6 additions & 6 deletions man/read_csv.Rd → man/fread_csv.Rd

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

12 changes: 6 additions & 6 deletions man/read_csv_numer.Rd → man/fread_csv_numer.Rd

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

12 changes: 6 additions & 6 deletions tests/testthat/test-read_issues.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test_that("read_cross2 deals with missing marker info", {

# drop two markers from the geno file
geno_file <- file.path(dir, "iron_geno.csv")
g <- read_csv(geno_file, rownames_included=FALSE)
g <- fread_csv(geno_file, rownames_included=FALSE)
dropped_index <- c(20,28)
dropped_markers <- colnames(g)[dropped_index]
write.table(g[,-dropped_index], file=geno_file, sep=",",
Expand All @@ -26,7 +26,7 @@ test_that("read_cross2 deals with missing marker info", {
# drop two markers from the gmap file
# and give another two missing positions
gmap_file <- file.path(dir, "iron_gmap.csv")
gmap <- read_csv(gmap_file, rownames_included=FALSE)
gmap <- fread_csv(gmap_file, rownames_included=FALSE)
dropped_index2 <- c(14, 51)
dropped_markers2 <- gmap[dropped_index2,1]
na_index2 <- c(5, 56)
Expand All @@ -45,7 +45,7 @@ test_that("read_cross2 deals with missing marker info", {
# drop two markers from the pmap file
# and give another one a missing position
pmap_file <- file.path(dir, "iron_pmap.csv")
pmap <- read_csv(pmap_file, rownames_included=FALSE)
pmap <- fread_csv(pmap_file, rownames_included=FALSE)
dropped_index3 <- c(4, 29)
dropped_markers3 <- pmap[dropped_index3,1]
na_index3 <- 33
Expand All @@ -58,7 +58,7 @@ test_that("read_cross2 deals with missing marker info", {
expect_equal(iron_sub3, drop_markers(iron, c(dropped_markers, dropped_markers3, na_markers3)))

# markers out of order in genotypes
g <- read_csv(geno_file)
g <- fread_csv(geno_file)
g <- g[,sample(ncol(g)),drop=FALSE]
write.table(cbind(marker=rownames(g), g), file=geno_file, sep=",",
row.names=FALSE, col.names=TRUE, quote=FALSE)
Expand All @@ -67,7 +67,7 @@ test_that("read_cross2 deals with missing marker info", {
expect_equal(iron_sub3, iron_randgeno)

# markers out of order in physical map
pmap <- read_csv(pmap_file, rownames_included=FALSE)
pmap <- fread_csv(pmap_file, rownames_included=FALSE)
pmap_rand <- pmap
pmap_rand <- pmap[sample(nrow(pmap)), , drop=FALSE]
write.table(pmap_rand, file=pmap_file, sep=",",
Expand All @@ -77,7 +77,7 @@ test_that("read_cross2 deals with missing marker info", {
expect_equal(iron_sub3, iron_randpmap)

# markers out of order within a chromosome on genetic map
gmap <- read_csv(gmap_file, rownames_included=FALSE)
gmap <- fread_csv(gmap_file, rownames_included=FALSE)
gmap_reordered <- gmap
gmap_reordered[6:7,1] <- gmap[7:6,1] # swap two marker names
write.table(gmap_reordered, file=gmap_file, sep=",",
Expand Down

0 comments on commit 83301f7

Please sign in to comment.