Closed
Description
The below code worked in padr 0.1.0, but breaks in padr 0.2.0. The issue seems to be that the new version of the pad function cannot identify that my by column name is in my dataframe.
library(magrittr)
library(padr)
sample_df = data.frame(
dates = as.Date(c("1946-03-28", "1947-03-25", "1950-04-17")),
data = c(120, 665, 2001))
sample_df2 = sample_df %>% thicken(interval="year", by="dates", colname="even_dates")
sample_df2 %>% pad(interval="year", by="even_dates")
# I get this error -> Error: by name not found in the column names
To help diagnose the issue, I ran the pad (and check_date_variable) functions from scratch and traced back the error.
library(magrittr)
#library(padr)
source("pad.R")
source("check_date_variables.R")
sample_df = data.frame(
dates = as.Date(c("1946-03-28", "1947-03-25", "1950-04-17")),
data = c(120, 665, 2001))
sample_df2 = sample_df %>% thicken(interval="year", by="dates", colname="even_dates")
sample_df2
sample_df2 %>% pad(interval="year", by="even_dates")
traceback()
#12: stop("by name not found in the column names", call. = FALSE) at check_date_variables.R#13
#11: check_data_frame(x, by = by_val) at pad.R#118
#10: pad_single(x, interval = interval, start_val = start_val, end_val = end_val,
# by = by, group = NULL) at pad.R#75
#9: pad(., interval = "year", by = "even_dates")
#8: function_list[[k]](value)
#7: withVisible(function_list[[k]](value))
#6: freduce(value, `_function_list`)
#5: `_fseq`(`_lhs`)
#4: eval(expr, envir, enclos)
#3: eval(quote(`_fseq`(`_lhs`)), env, env)
#2: withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
#1: sample_df2 %>% pad(interval = "year", by = "even_dates")
I added a little debug printing and I think the issue is that your use of match.call within the pad_single function is not returning the original function's arguments because it's nested within the pad function. Instead, it's just returning the names used when you passed those arguments to pad_single (e.g. by_val is not the name of the column but literally a string "by").
> sample_df2 %>% pad(interval="year", by="even_dates")
# For reference, debug printing is happening right after Line 112 in pad.R
[1] "arguments"
[[1]]
pad_single
$x
x
$interval
interval
$start_val
start_val
$end_val
end_val
$by
by
$group
NULL
[1] "by"
[1] "even_dates"
[1] "by_val"
[1] "by"
Metadata
Metadata
Assignees
Labels
No labels