brad-cannell / codebookr

Create Codebooks From Data Frames
https://brad-cannell.github.io/codebookr/
Other
26 stars 7 forks source link

Codebookr - L2C Master Log #9

Closed areddy647712 closed 2 years ago

areddy647712 commented 2 years ago

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

mbcann01 commented 2 years ago

Thank you!

mbcann01 commented 2 years ago

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.