Is stargazer interpreting data.frame data as latex code, is it a bug, or is it intended?

I have a problem when the Stargazer function interprets the data in my data.frame as latex. I would like to find a way to suppress this star feature. See below.

z <- c("Bank of America Corp", "Citigroup Inc", "JPMorgan Chase & Co", "Morgan Stanley", "Wells Fargo & Co") s <- data.frame(z=z, l= c(100000, 25, 10000, 24, 100000)) library(stargazer) stargazer(s, type = "text", summary = FALSE) # prints out ============================== zl ------------------------------ 1 Bank of America Corp 100,000 2 Citigroup Inc 25 3 JPMorgan Chase Co 4 Morgan Stanley 24 5 Wells Fargo Co ------------------------------ 

Here the ampersand invokes a new column due to its value in latex. I confirmed this because I replaced both s and made the table print correctly.

  z <- c("Bank of America Corp", "Citigroup Inc", "JPMorgan Chase and Co", "Morgan Stanley", "Wells Fargo and Co") s <- data.frame(z=z, l= c(100000, 25, 10000, 24, 100000)) library(stargazer) stargazer(s, type = "text", summary = FALSE) # prints out =============================== zl ------------------------------- 1 Bank of America Corp 100,000 2 Citigroup Inc 25 3 JPMorgan Chase and Co 10,000 4 Morgan Stanley 24 5 Wells Fargo and Co 100,000 ------------------------------- 

Is there any parameter that I can call in the stargazer function to prevent this behavior?

+6
source share
1 answer

There seems to be no way for this version with the current version of stargazer. If you check the source code, you will find the following code snippet (line 4704):

 ############## TEXT AND html MODE ############## .split.line <- # split line of a LaTeX table into constituent parts separated by & function(s) { # remove the "\\\\" s <- gsub("\\\\", "", s, fixed=TRUE) s <- paste(" ",s," ", sep="") return(.trim(strsplit(s, " &", fixed=TRUE)[[1]])) } 

So it looks like it seems to be hardcoded in how stargazer formats the output of the table and is not captured by any variant of the command.

If you just want to format a data frame similar to the one you posted in your example, I would use print.xtable() from the xtable package, which has a sanitize function that correctly processes ampersands in strings and creates LaTeX and HTML outupt as valid the proposed example data frame.

+4
source

Source: https://habr.com/ru/post/985219/


All Articles