-
-
Save alexeyknorre/b0780836f4cec04d41a863a683f91b53 to your computer and use it in GitHub Desktop.
| ## Quick fix for stargazer <= 5.2.3 is.na() issue with long model names in R >= 4.2 | |
| # Unload stargazer if loaded | |
| detach("package:stargazer",unload=T) | |
| # Delete it | |
| remove.packages("stargazer") | |
| # Download the source | |
| download.file("https://cran.r-project.org/src/contrib/stargazer_5.2.3.tar.gz", destfile = "stargazer_5.2.3.tar.gz") | |
| # Unpack | |
| untar("stargazer_5.2.3.tar.gz") | |
| # Read the sourcefile with .inside.bracket fun | |
| stargazer_src <- readLines("stargazer/R/stargazer-internal.R") | |
| # Move the length check 5 lines up so it precedes is.na(.) | |
| stargazer_src[1990] <- stargazer_src[1995] | |
| stargazer_src[1995] <- "" | |
| # Save back | |
| writeLines(stargazer_src, con="stargazer/R/stargazer-internal.R") | |
| # Compile and install the patched package | |
| install.packages("stargazer", repos = NULL, type="source") |
thank you, alexey!
Thank you, alexey. You've done me a big favor.
I still get an error if I include more than 4 regression results in stargazer.
Thank you, Alexey. You save me!
Thank you, Alexey !
Thank you so much! The tables in my thesis would not be possible without your solution. I was able to put the results of 8 Probits into a table without problems.
Thanks a lot!!!
Great fix.
Great fix, thank you!
Very useful, thank you!
I have slightly adapted your patch to put it in the .Rprofile of a repository, that can be used by anyone seemlessly, even if the user already has stargazer installed:
if (!is.element("stargazer", installed.packages()[,1]) || packageVersion("stargazer") != "5.2.3.42") {
temp <- getwd()
setwd(.libPaths()[1])
tryCatch({ detach("package:stargazer", unload=T)}, error = function(cond) { print("This is just a warning: stargazer not loaded yet.") } )
tryCatch({ remove.packages("stargazer")}, error = function(cond) { print("This is just a warning: stargazer not found.") } )
download.file("https://cran.r-project.org/src/contrib/stargazer_5.2.3.tar.gz", destfile = "stargazer_5.2.3.tar.gz")
untar("stargazer_5.2.3.tar.gz") # If it doesn't work, re-open RStudio in administrator mode
stargazer_src <- readLines("stargazer/R/stargazer-internal.R")
stargazer_src[1990] <- stargazer_src[1995]
stargazer_src[1995] <- ""
writeLines(stargazer_src, con="stargazer/R/stargazer-internal.R")
stargazer_description <- readLines("stargazer/DESCRIPTION")
stargazer_description[4] <- "Version: 5.2.3.42"
writeLines(stargazer_description, con="stargazer/DESCRIPTION")
install("stargazer")
setwd(temp)
}
library(stargazer)
@alexeyknorre thank you soooo much, your generosity in sharing this solution has restored my faith in humanity. Have a great week
My hero!!!!
just worked for me when nothing else would. appreciate it!
Thank you! This was a very quick and easy fix. Much appreciated.
You are quite brilliant! It helps me a lot!
Thanks a lot for this solution! You are a life saver)