Skip to content

improve error when invalid item_parameters is passed to block_design #50

@pdbailey0

Description

@pdbailey0

I used block_design and passed it a item_parameters with column item that was the integers from 1:nrow(item_parameters) this caused a very difficult to read error.

Error in rep(0, (max(block_len) - length(block_items))) : 
  invalid 'times' argument

There are many possible fixes for this. for my purposes, it worked to just overwrite item to be 1:nrow(item_parameters), but doing that would cause issues if you expected to know the item column outside of block_design, so I made a fork that instead just gives a helpful error an exists.

Minimal working example:

param <- NAEPirtparams::parameters
item_par <- param[param$level %in% 8 & param$subject %in% "Mathematics" & param$year %in% 2015, ]
item_par$item <- sample(1:1e5, nrow(item_par))
item_par <- item_par[1:32,]
# this gives the error I share above about invalid `times` argument
block <- lsasim::block_design(n_blocks = 10, item_parameters = item_par)

My proposed version makes this error

devtools::install_github("pdbailey0/lsasim")
param <- NAEPirtparams::parameters
item_par <- param[param$level %in% 8 & param$subject %in% "Mathematics" & param$year %in% 2015, ]
item_par$item <- sample(1:1e5, nrow(item_par))
item_par <- item_par[1:32,]
block <- lsasim::block_design(n_blocks = 10, item_parameters = item_par)
# Error in lsasim::block_design(n_blocks = 10, item_parameters = item_par) : 
#   the item_parameters argument must have a column named item that contains the integers from one to the number of rows in item_parameters

I think fixed my bug with

item_par$item <- 1:32
# now it runs fine
block <- lsasim::block_design(n_blocks = 10, item_parameters = item_par)

If you like this, I'll propose a pull request for you to review.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions