This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# base plot | |
ggplot(mtcars, aes(x = mpg, y = hp)) + | |
geom_point() | |
# Ensure that the legend is single line (e.g. at the bottom) | |
# I need to use guide_legend() because it is discrete | |
# use guide_colorbar() for continuous | |
ggplot(mtcars, aes(x = mpg, y = hp, color = cyl)) + | |
geom_point() + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(xfun) | |
gsub_dir(dir = "R", pattern = "mutate\\(", replacement = "dplyr::mutate\\(") | |
gsub_dir(dir = "R", pattern = "select\\(", replacement = "dplyr::select\\(") | |
gsub_dir(dir = "R", pattern = "filter\\(", replacement = "dplyr::filter\\(") | |
gsub_dir(dir = "R", pattern = "bind_rows\\(", replacement = "dplyr::bind_rows\\(") | |
gsub_dir(dir = "R", pattern = "bind_cols\\(", replacement = "dplyr::bind_cols\\(") | |
gsub_dir(dir = "R", pattern = "case_when\\(", replacement = "dplyr::case_when\\(") | |
gsub_dir(dir = "R", pattern = "left_join\\(", replacement = "dplyr::left_join\\(") | |
gsub_dir(dir = "R", pattern = "full_join\\(", replacement = "dplyr::full_join\\(") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# read in the initial bib file | |
tex <- readLines("test.bib") | |
# get the location of the titles (NOTE: also will include fields of the nature 'booktitle') | |
title_loc <- grepl("title", tex, fixed = TRUE) | |
# Change the opening bracket from { to {{ | |
# the full regex looks for strings containing 'title = {,' or 'title={' and replaces it with 'title = {' | |
tex[title_loc] <- gsub("title = \\{|title=\\{","title = {{",tex[title_loc]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# check out all info here: https://r-pkgs.org/release.html | |
# update NEWS | |
# udpate cran-comments.Rd | |
tools::resaveRdaFiles("data/") | |
# build the tarball and check whether the size is below 5 MB | |
devtools::build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: oxforddown explanation in the chapter on tables | |
library(kableExtra) | |
head(mtcars) %>% | |
kable(booktabs = TRUE) %>% | |
kable_styling(latex_options = "scale_down") | |
a_long_table <- rbind(mtcars, mtcars) | |
a_long_table %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kable(foo, format = "latex", booktabs = T, row.names = FALSE, linesep = "", escape = FALSE) %>% | |
kable_styling(latex_options = c("striped")) %>% | |
group_rows("$\\\\text{Group1}^a$", 1, 2, escape = FALSE) %>% | |
group_rows(paste0("Group2\\\\", footnote_marker_alphabet(1), sep = ""), 3, 4, escape = FALSE) %>% | |
# I don't think expression() is helpful, doesn't seem to get converted | |
# to latex | |
group_rows(expression("Group3"^a), 5, 6) %>% | |
group_rows("Group4\\\\textsuperscript{a}", 7, 8, escape = FALSE) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to get to the recover list - allows you to walk through all frames | |
options(error = recover) | |
# to get back from a call to the options page again, use `c` | |
# just loading any library to try these functions out | |
library(gets) | |
# trace will execute any function when you execute the first function | |
# e.g. it will execute `browser` when I execute `getsm` | |
trace(getsm, browser) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
logLik.plm <- function(object){ | |
out <- -plm::nobs(object) * log(2 * var(object$residuals) * pi)/2 - deviance(object)/(2 * var(object$residuals)) | |
attr(out,"df") <- nobs(object) - object$df.residual | |
attr(out,"nobs") <- plm::nobs(object) | |
return(out) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(plm) | |
library(tidyverse) | |
library(fastDummies) | |
data(EmplUK) | |
EmplUK %>% | |
select(-sector) %>% | |
dummy_cols(.data = .,select_columns = c("firm","year"),remove_selected_columns = TRUE,remove_first_dummy = TRUE) -> paneldata | |
head(paneldata) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lapply(ls(), function(o) assign(x = o, value = get(o), envir = .GlobalEnv)) |
NewerOlder