Skip to content

Commit

Permalink
1:k -> seq_len(k)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Nov 4, 2017
1 parent 5873b24 commit b7ac6e2
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion R/as_sample_tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ as_sample_tibble.stanreg = function(model) {
#so we dont' just do as_sample_tibble(model$stanfit)
sample_matrix = as.array(model) #[iteration, chain, parameter]
n_chain = dim(sample_matrix)[[2]]
mcmc_list = as.mcmc.list(lapply(1:n_chain, function(chain) as.mcmc(sample_matrix[, chain, ]))) # nolint
mcmc_list = as.mcmc.list(lapply(seq_len(n_chain), function(chain) as.mcmc(sample_matrix[, chain, ]))) # nolint
as_sample_tibble(mcmc_list)
}

Expand Down
4 changes: 2 additions & 2 deletions R/compose_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ as_data_list.character = function(object, name="", ...) {
as_data_list.list = function(object, name="", ...) {
#go through list and translate variables
data = data_list()
for (i in 1:length(object)) {
for (i in seq_along(object)) {
data = c(data, as_data_list(object[[i]], name = names(object)[[i]], ...))
}
data
Expand Down Expand Up @@ -258,7 +258,7 @@ compose_data = function(..., .n_name = n_prefix("n")) {
#convert objects into a data list one by one, evaluating each argument in the
#environment of the previous lists (to allow the user to refer to previously composed elements)
data = list()
for (i in 1:length(exprs)) {
for (i in seq_along(exprs)) {
object_to_compose = eval_tidy(exprs[[i]], data)

# lists and data frames don't use names unless they were provided explicitly
Expand Down
2 changes: 1 addition & 1 deletion R/predict_curve.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ predict_curve = function(data, formula, summary = median, ...) {
eval(bquote(
do(data, {
#for every group defined in data ...
ldply(1:nrow(varied_predictors), function(r) {
ldply(seq_len(nrow(varied_predictors)), function(r) {
#and for every prediction point on the curve
#defined by the values in (...)
predictor_row = as.list(varied_predictors[r, , drop = FALSE]) # nolint
Expand Down
2 changes: 1 addition & 1 deletion R/recover_types.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ as_constructor.default = function(x) identity
as_constructor.factor = function(x) {
x_levels = levels(x)
x_is_ordered = is.ordered(x)
function(x) factor(x, levels = 1:length(x_levels), labels = x_levels, ordered = x_is_ordered)
function(x) factor(x, levels = seq_along(x_levels), labels = x_levels, ordered = x_is_ordered)
}

as_constructor.character = function(x) as_constructor(as.factor(x))
Expand Down
2 changes: 1 addition & 1 deletion R/x_at_y.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ x_at_y = function(x, y, missing = NA) {
if (min(y) < 1) {
stop(paste0("All values of ", y_label, " must be >= 1. Got min(", y_label, ") == ", min(y)))
}
1:max(y)
seq_len(max(y))
} else {
stop(paste0(
"Cannot generate a lookup table for non-numeric / non-factor variable: ",
Expand Down
2 changes: 1 addition & 1 deletion build_test_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ library(brms)


mtcars_tbl = mtcars %>%
set_rownames(1:nrow(.)) %>%
set_rownames(seq_len(nrow(.))) %>%
as_data_frame()


Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test.add_fitted_samples.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ context("fitted_samples")

# data
mtcars_tbl = mtcars %>%
set_rownames(1:nrow(.)) %>%
set_rownames(seq_len(nrow(.))) %>%
as_data_frame()


Expand Down Expand Up @@ -73,7 +73,7 @@ test_that("[add_]fitted_samples works on brms models without auxpars", {

fits = fitted(m_hp, mtcars_tbl, summary = FALSE) %>%
as.data.frame() %>%
set_names(1:ncol(.)) %>%
set_names(seq_len(ncol(.))) %>%
mutate(
.chain = as.integer(NA),
.iteration = seq_len(n())
Expand All @@ -97,7 +97,7 @@ test_that("[add_]fitted_samples works on brms models with auxpars", {

fits = fitted(m_hp_sigma, mtcars_tbl, summary = FALSE) %>%
as.data.frame() %>%
set_names(1:ncol(.)) %>%
set_names(seq_len(ncol(.))) %>%
mutate(
.chain = as.integer(NA),
.iteration = seq_len(n())
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test.add_predicted_samples.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ context("predicted_samples")

# data
mtcars_tbl = mtcars %>%
set_rownames(1:nrow(.)) %>%
set_rownames(seq_len(nrow(.))) %>%
as_data_frame()


Expand Down Expand Up @@ -74,7 +74,7 @@ test_that("[add_]predicted_samples works on a simple brms model", {
set.seed(123)
preds = predict(m_hp, mtcars_tbl, summary = FALSE) %>%
as.data.frame() %>%
set_names(1:ncol(.)) %>%
set_names(seq_len(ncol(.))) %>%
mutate(
.chain = as.integer(NA),
.iteration = seq_len(n())
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test.gather_emmeans_samples.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ context("gather_emmeans_samples")

# data
mtcars_tbl = mtcars %>%
set_rownames(1:nrow(.)) %>%
set_rownames(seq_len(nrow(.))) %>%
as_data_frame()


Expand All @@ -31,7 +31,7 @@ test_that("gather_emmeans_samples works on a simple rstanarm model", {
as.data.frame() %>%
mutate(
.chain = as.integer(NA),
.iteration = as.integer(1:n())
.iteration = seq_len(n())
) %>%
gather(.row, estimate, -.chain, -.iteration) %>%
as_data_frame()
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test.point_interval.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ get_samples = function() {
ldply(1:18, function(i) {
data.frame(
.chain = 1,
.iteration = 1:nrow(RankCorr),
.iteration = seq_len(nrow(RankCorr)),
ff = ff_labels[i],
tau = RankCorr[, paste0("tau[", i, "]")]
)
Expand Down

0 comments on commit b7ac6e2

Please sign in to comment.