Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bed_intersect function convert factor columns to numeric #360

Closed
frequena opened this issue Apr 23, 2020 · 4 comments · Fixed by #361
Closed

bed_intersect function convert factor columns to numeric #360

frequena opened this issue Apr 23, 2020 · 4 comments · Fixed by #361
Labels

Comments

@frequena
Copy link

frequena commented Apr 23, 2020

When I use the function "bed_intersect", any factor column in the input is converted automatically to an integer column. The same column as a character type, it does not change.

Example:

library(valr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

tibble(chrom = '1', start = 1, end = 10, pathogenic = factor(c('Yes'))) %>%
  bed_intersect(tibble(chrom = '1', start = 1, end = 5))
#> # A tibble: 1 x 8
#>   chrom start.x end.x pathogenic.x start.y end.y .source .overlap
#>   <chr>   <dbl> <dbl>        <int>   <dbl> <dbl> <chr>      <int>
#> 1 1           1    10            1       1     5 1              4

tibble(chrom = '1', start = 1, end = 10, pathogenic = c('Yes')) %>%
  bed_intersect(tibble(chrom = '1', start = 1, end = 5))
#> # A tibble: 1 x 8
#>   chrom start.x end.x pathogenic.x start.y end.y .source .overlap
#>   <chr>   <dbl> <dbl> <chr>          <dbl> <dbl> <chr>      <int>
#> 1 1           1    10 Yes                1     5 1              4

Created on 2020-04-23 by the reprex package (v0.3.0)

@jayhesselberth
Copy link
Member

jayhesselberth commented Apr 23, 2020

Thanks for the clear example, this looks like a bug in how factors are handled internally.

@jayhesselberth jayhesselberth added this to the 0.6.0 milestone Apr 23, 2020
@kriemo
Copy link
Member

kriemo commented Apr 23, 2020

Yes, this is a bug, thanks for bringing this issue to our attention. I see how to fix this but will need to do some testing prior to pushing as it affects some c++ internals.

@kriemo
Copy link
Member

kriemo commented Apr 23, 2020

This should be fixed on master now. Please reinstall from github to fix this issue. Thanks.

devtools::install_github("rnabioco/valr")

@frequena
Copy link
Author

It works! Perfect, thank you very much for your work, valr is really useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants