Search code examples
rflextable

How do you call internal functions?


I'm working on a script given to me and was given the following error:

Error in get_rows_id(x[[part]], i) : 
  invalid row selection: out of range selection

I tried searching for the get_rows_id function within the script but couldn't find it. So I ran list.files on all the packages to see where it was coming from and realized it was from the flextable package:

list.files(system.file(package = 'flextable'), recursive = T, full.names = T)) 

I didn't see anything using browser where flextable was used.

Is there another way non-exported functions can be called or hidden within another function in the script?

The only other way I have found to run an internal function would be

flextable:::get_rows_id

but that's a direct way I don't see in the script.

Here's the portion with flextable:

  df %>% 
    #  opts
    flextable(cheight = cell_height) %>% 
    add_footer_lines(top = F, values = source_caption(report_quarter)) %>%
    style(pr_p = def_par, pr_t = def_text, pr_c = def_cell, part = "all") %>% 
    style(pr_c = def_header_bg, 
          pr_t = def_text_header, 
          part = "header") %>% 
    style(j = 1, pr_p = update(text.align = "left", def_par), 
          part = "body") %>% 
    style(pr_p = update(text.align = "left", def_par), 
          pr_c = update(vertical.align = "bottom", border.bottom = fp_border(width = 0), def_cell), 
          pr_t = update(color = cbre_pal[2], def_text), 
          part = "footer") %>% 
    style(i = which(submarket_order %in% totals), 
          j = 1,
          pr_t = update(bold = T, def_text)) %>% 
    ## Row borders
    border(border.top = body_border, border.bottom = body_border,
           part = "body") %>% 
    width(width = cell_width) %>% 
    width(j = 1, 1.55) %>% 
    height(height = .28, part = "header") %>% # changed from .65
    void(1, part = "header")

Solution

  • I wasn't able to figure out how to call the internal function other than flextable:::get_rows_id. However, I was able to solve the issue by place browser () in one of my other functions that called my df. Turns out the bug was further up in the call sequence. If you're in the same boat your best bet is to just look at everything that's interacting with said function. Hope I was able to help, good luck.