Error: Warning: Error in rep: invalid 'times' argument

Hi,
I have been using knitr::kable to produce a table from a matrix. The code:

 m.OutTab <- as.matrix(m.OutTab)
  m.OutTab <- gsub("NA%","",m.OutTab)
  #Additional Suppressions
  m.OutTab <- gsub("NaN%","",m.OutTab)
  m.OutTab <- gsub("Inf%","",m.OutTab)
  
  
  
  if(nchar(placename) != 0) {
    names_spaced <- c("Year","Population","Growth Rate","Population","Growth Rate","Population","Growth Rate") 
    tblHead <- c(" " = 1, placename = 2, ctyname = 2, state = 2)
    names(tblHead) <- c(" ", placename, ctyname,state)
  } else {
    names_spaced <- c("Year","Population","Growth Rate","Population","Growth Rate")
    tblHead <- c(" " = 1, ctyname = 2, state = 2)
    names(tblHead) <- c(" ", ctyname,state)
  }

     OutTab  <- m.OutTab %>%
        kable(format='html', table.attr='class="myTable"',
              caption = "Population Growth Rate",
              row.names=FALSE,
              align='lrrrr',
              col.names = names_spaced,
              escape = FALSE) %>%
        kable_styling(bootstrap_options = "condensed") %>%
        column_spec(1, width = "0.4in") %>%
        column_spec(2, width = "0.5in") %>%
        column_spec(3, width = "0.5in") %>%
        column_spec(4, width = "0.5in") %>%
        column_spec(5, width = "0.5in") %>%
        add_header_above(header=tblHead)  %>%
        add_footnote(captionSrc("SDO",""))

Out of nowhere I have been getting the following error in my development version of R
Warning: Error in rep: invalid 'times' argument
The error occurs at the creation of OutTab, the kable table.
I mean, really out of nowhere. This code has been running on out web server for the past 6 months without a problem.

Any ideas about why this is happening?
TIA

sessionInfo() and some sample data (a dput() of the starting m.Out.Tab will do nicely) are going to be important for trying to sort this out, I think.

Am I understanding correctly that you’re only seeing the problem on an R-devel build of R? If so, it may not be worth tracking down a fix β€” the R development snapshots are likely to contain bugs and/or changes that package authors haven’t adapted to yet. Why not stick to an official release?

Some clarifications
By "development" I meant the latest version of R (R version 3.5.0 (2018-04-23)) and the latest version of R Studio (Version 1.1.442) running on my local computer. The code snippets are from a shiny app we have developed.

The data frame (m.OutTab) is as follows:

year Population GrowthRate Population.1 GrowthRate.1
1990 265,708 NA% 3,304,042 NA%
1995 312,593 3.30% 3,811,074 2.90%
2000 351,735 2.40% 4,338,801 2.60%
2005 395,384 2.40% 4,662,534 1.40%
2010 443,711 2.30% 5,050,332 1.60%
2015 489,923 2.00% 5,448,055 1.50%
2016 497,673 1.60% 5,538,180 1.70%

In the data frame, "year" is numeric but all of the other variables are character.

HTH
AB

I have located the error,
The " add_footnote(captionSrc("SDO",""))" command is causing the error. The command itself is the problem, I replaced my function call (captionSrc(...)) with a string and still got the error.

Does anyone have any idea what happened to kable_styling to cause this behavior?

I really feel stupid, but I solved the issue by changing the "add_footnote..." command with a "footnote..." command, per the kableExtra documentation.

Why this would work is anyone's guess. It seems to me that this is a compatibility issue, there was an update to kableExtra a while back. Apparently the new version was not backward compatible.

So it goes. Now I need to update the rest of my shiny app.
Cheers

I'm glad you found a solution that's working for you! Oddly, I wasn't able to reproduce the error:

library(magrittr)
library(kableExtra)

m.OutTab <- readr::read_csv(
  "year,Population,GrowthRate,Population.1,GrowthRate.1
  1990,265708,NA%,3304042,NA%
  1995,312593,3.30%,3811074,2.90%
  2000,351735,2.40%,4338801,2.60%
  2005,395384,2.40%,4662534,1.40%
  2010,443711,2.30%,5050332,1.60%
  2015,489923,2.00%,5448055,1.50%
  2016,497673,1.60%,5538180,1.70%"
)

ctyname <- "Starling City"
state <- "This State"

names_spaced <- c("Year", "Population", "Growth Rate", "Population", "Growth Rate")
tblHead <- c(" " = 1, ctyname = 2, state = 2)
names(tblHead) <- c(" ", ctyname, state)

OutTab  <- m.OutTab %>%
  knitr::kable(format = 'html', table.attr = 'class="myTable"',
        caption = "Population Growth Rate",
        row.names = FALSE,
        align ='lrrrr',
        col.names = names_spaced,
        escape = FALSE) %>%
  kable_styling(bootstrap_options = "condensed") %>%
  column_spec(1, width = "0.4in") %>%
  column_spec(2, width = "0.5in") %>%
  column_spec(3, width = "0.5in") %>%
  column_spec(4, width = "0.5in") %>%
  column_spec(5, width = "0.5in") %>%
  add_header_above(header = tblHead)  %>%
  add_footnote("This is the footnote for the table!")

Created on 2018-06-29 by the reprex package (v0.2.0).

14

> sessioninfo::session_info()
─ Session info ──────────────────────
 setting  value                       
 version  R version 3.5.0 (2018-04-23)
 os       Ubuntu 16.04.4 LTS          
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language (EN)                        
 collate  C.UTF-8                     
 tz       Etc/UTC                     
 date     2018-06-29                  

─ Packages ──────────────────────────────────
 package     * version date       source        
 backports     1.1.2   2017-12-13 RSPM (R 3.5.0)
 clisymbols    1.2.0   2017-05-21 RSPM (R 3.5.0)
 colorspace    1.3-2   2016-12-14 RSPM (R 3.5.0)
 digest        0.6.15  2018-01-28 RSPM (R 3.5.0)
 evaluate      0.10.1  2017-06-24 RSPM (R 3.5.0)
 hms           0.4.2   2018-03-10 RSPM (R 3.5.0)
 htmltools     0.3.6   2017-04-28 RSPM (R 3.5.0)
 httr          1.3.1   2017-08-20 RSPM (R 3.5.0)
 kableExtra  * 0.9.0   2018-05-21 RSPM (R 3.5.0)
 knitr         1.20    2018-02-20 RSPM (R 3.5.0)
 magrittr    * 1.5     2014-11-22 RSPM (R 3.5.0)
 munsell       0.5.0   2018-06-12 RSPM (R 3.5.0)
 pillar        1.2.3   2018-05-25 RSPM (R 3.5.0)
 pkgconfig     2.0.1   2017-03-21 RSPM (R 3.5.0)
 plyr          1.8.4   2016-06-08 RSPM (R 3.5.0)
 R6            2.2.2   2017-06-17 RSPM (R 3.5.0)
 Rcpp          0.12.17 2018-05-18 RSPM (R 3.5.0)
 readr         1.1.1   2017-05-16 RSPM (R 3.5.0)
 rlang         0.2.1   2018-05-30 RSPM (R 3.5.0)
 rmarkdown     1.10    2018-06-11 RSPM (R 3.5.0)
 rprojroot     1.3-2   2018-01-03 RSPM (R 3.5.0)
 rstudioapi    0.7     2017-09-07 RSPM (R 3.5.0)
 rvest         0.3.2   2016-06-17 RSPM (R 3.5.0)
 scales        0.5.0   2017-08-24 RSPM (R 3.5.0)
 sessioninfo   1.0.0   2017-06-21 RSPM (R 3.5.0)
 stringi       1.2.3   2018-06-12 RSPM (R 3.5.0)
 stringr       1.3.1   2018-05-10 RSPM (R 3.5.0)
 tibble        1.4.2   2018-01-22 RSPM (R 3.5.0)
 viridisLite   0.3.0   2018-02-01 RSPM (R 3.5.0)
 withr         2.1.2   2018-03-15 RSPM (R 3.5.0)
 xml2          1.2.0   2018-01-24 RSPM (R 3.5.0)

(I ran this in a new project on RStudio Cloud)

1 Like