brad-cannell/codebookr

Codebookr - L2C Master Log

Closed this issue · 2 comments

Hi Brad,

This is the error I received when passing the Master Log data frame to the codebook function.

Error in dplyr::mutate():
! Problem while computing Value = date.
Value must be a vector, not a function.

These are the steps I took:

  1. Load Master_Log version2
  2. glimpse(Master_Log version2)
  3. Pass the data frame to the codebook function

I hope this was helpful. I also tried to use the cb_add_col_attributes() function and assign attributes to columns with dates in them.

Thank you!
Aish

Thank you!

POSIXct issue

It looks like this error is caused by POSIXct columns. I'm not sure why yet. It also looks like the code that is struggling is on lines 72-76 of cb_summary_stats_time.R

It doesn't look like the problem is with a POSIXct column per se. The date_time column I created in the example study data works just fine. Not, sure what the problem is.

The problem is with calculating the mode when there is a mode value (as opposed to all values occurring exactly one time).

The section of code that calculates the mode value still had the date column hardcoded into it from when I originally created and test the function. This explains why the date column had a mode value and didn't throw an error, but other columns with mode value did.

mode <- df %>%
      dplyr::count(.data[[.x]], name = "Frequency") %>%
      dplyr::filter(Frequency == max(Frequency)) %>%
      dplyr::mutate(
        Statistic = "Mode",
        Percentage = Frequency / nrow(df) * 100,
        Value = date
      )

Changing the last line Value = date to Value = .data[[.x]] fixes the problem.

  • Update the study data to include a POSIXct column
  • Fix the problem
  • Unit test (decided I don't really need this. The code for the new test wasn't any different than the code for the previous test. It was just a different column name).
  • Update documentation
  • Check
  • Merge to main
  • Install
  • Push