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

Helper functions for consuming iterators #41

Open
ramhiser opened this issue Aug 2, 2015 · 1 comment
Open

Helper functions for consuming iterators #41

ramhiser opened this issue Aug 2, 2015 · 1 comment

Comments

@ramhiser
Copy link
Owner

ramhiser commented Aug 2, 2015

Writing unlist(as.list(it)) gets kind of old. Plus, it can get weird when it returns something more than a single numeric or character. With this in mind, helper functions are a must. Something along the lines of:

  • to_list
  • to_vector
  • to_dataframe
@ramhiser
Copy link
Owner Author

In my own code, I've been using as_vector and as_numeric as:

as_vector <- function(x) {
  unlist(as.list(x))
}

set.seed(42)
it <- irep(function(x) rnorm(1), times=10)
as_vector(it)
# [1]  1.37095845 -0.56469817  0.36312841  0.63286260  0.40426832 -0.10612452  1.51152200 -0.09465904
# [9]  2.01842371 -0.06271410
as_numeric <- function(x) {
  as.numeric(as.list(x))
}
set.seed(42)
it <- irep(function(x) rnorm(1), times=10)
as_numeric(it)
# [1]  1.37095845 -0.56469817  0.36312841  0.63286260  0.40426832 -0.10612452  1.51152200 -0.09465904
# [9]  2.01842371 -0.06271410

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

No branches or pull requests

1 participant