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

update intervaltree #391

Merged
merged 7 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# valr (development version)

* Updated [intervalTree](https://github.com/ekg/intervaltree) header to commit f0c4046

* valr now uses [cli](https://cli.r-lib.org/index.html) for more consistent
errors and messages during interactive use.

* deprecated `genome` argument to `bed_makewindows()` was removed.


# valr 0.6.5

* Handle `max_dist` for first intervals in `bed_cluster()` (#388)
Expand Down
34 changes: 13 additions & 21 deletions inst/include/DataFrameBuilder.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// DataFrameBuilder.h
//
// Copyright (C) 2016 - 2018 Jay Hesselberth and Kent Riemondy
// Copyright (C) 2016 - 2022 Jay Hesselberth and Kent Riemondy
//
// This file is part of valr.
//
Expand All @@ -15,26 +15,18 @@
class DataFrameBuilder {
public:
std::vector<std::string> names ;
std::vector<SEXP> data ; // set to SEXP to handle any R type vector
List data ;
DataFrameBuilder() {} ;

// output List with: List out = DataFrameBuilder
inline operator List() const {
List out = wrap(data) ;
return out ;
return data ;
}

inline size_t size() const {
return data.size() ;
}

// add vector to DataFrameBuilder
// non-SEXP objects should be passed with Rcpp::wrap(obj)
inline void add_vec(std::string name, SEXP x) {
names.push_back(name) ;
data.push_back(x) ;
}

// add dataframe to DataFrameBuilder with suffix
inline void add_df(const DataFrame& df,
std::string suffix = "",
Expand All @@ -50,8 +42,8 @@ class DataFrameBuilder {
} else if (drop_chrom) {
continue ;
}

this->add_vec(name, df[i]) ;
this->names.push_back(name) ;
this->data.push_back(df[i]) ;
}
}

Expand All @@ -69,25 +61,25 @@ class DataFrameBuilder {
if (name == "chrom" && drop_chrom) {
continue ;
}
this->add_vec(name, df[i]) ;
this->names.push_back(name) ;
this->data.push_back(df[i]) ;
}
}

// apply common attributes to output dataframe
// by default groups are stripped and tbl_df is returned
inline List format_df(int nrow) {
List res = *this ;
auto names = this->names ;

set_rownames(res, nrow) ;
res.attr("names") = names ;
set_rownames(this->data, nrow) ;
this->data.attr("names") = names ;

if (Rf_inherits(res, "grouped_df")) {
ValrGroupedDataFrame::strip_groups(res) ;
if (Rf_inherits(this->data, "grouped_df")) {
ValrGroupedDataFrame::strip_groups(this->data) ;
}

res.attr("class") = Rcpp::CharacterVector::create("tbl_df", "tbl", "data.frame") ;
return res ;
this->data.attr("class") = Rcpp::CharacterVector::create("tbl_df", "tbl", "data.frame") ;
return this->data ;
}
};

Expand Down
Loading