MahShaaban / pcr

Quality assessing, analyzing and testing the statistical significance of real-time quantitative PCR data
https://CRAN.R-project.org/package=pcr
GNU General Public License v3.0
27 stars 8 forks source link

`pcr_test` return error when passed `group_var` as a factor #11

Closed MahShaaban closed 5 years ago

MahShaaban commented 5 years ago

The testing function pcr_test returns an error when the group_var is a factor rather than a character

# load library
library(pcr)

# locate and read data
fl <- system.file('extdata', 'ct4.csv', package = 'pcr')
ct4 <- readr::read_csv(fl)
#> Parsed with column specification:
#> cols(
#>   ref = col_double(),
#>   target = col_double()
#> )

# make group variable
group <- rep(c('control', 'treatment'), each = 12)

# test using t-test
pcr_test(ct4,
         group_var = group,
         reference_gene = 'ref',
         reference_group = 'control',
         test = 't.test')
#> # A tibble: 1 x 5
#>   gene   estimate   p_value  lower  upper
#>   <chr>     <dbl>     <dbl>  <dbl>  <dbl>
#> 1 target   -0.685 0.0000343 -0.956 -0.414

# make group variable as factor
group <- factor(group, levels = c('control', 'treatment'))

# test using t-test
pcr_test(ct4,
         group_var = group,
         reference_gene = 'ref',
         reference_group = 'control',
         test = 't.test')
#> Warning in Ops.factor(ref, 1): '<' not meaningful for factors
#> Warning in Ops.factor(ref, nlev): '>' not meaningful for factors
#> Error in if (ref < 1 || ref > nlev) stop(gettextf("ref = %d must be in 1L:%d", : missing value where TRUE/FALSE needed

Created on 2019-09-24 by the reprex package (v0.2.1)