Skip to content

Instantly share code, notes, and snippets.

View JanMarvin's full-sized avatar

Jan Marvin Garbuszus JanMarvin

  • Düsseldorf, Germany
View GitHub Profile
@JanMarvin
JanMarvin / dim_around_the_worksheet.R
Created March 26, 2024 22:50
dims around the worksheet
library(openxlsx2)
packageVersion("openxlsx2")
# the dimensions go in here
dim_matrix <- matrix("", 20, 10)
# matrix of size 2 x 2
mm <- matrix(1:4, 2, 2)
dim_matrix[1, 1] <- wb_dims(x = mm, col_names = FALSE)
@JanMarvin
JanMarvin / german_voting_trends.R
Created January 26, 2024 10:04
Voting trend in spreadsheet
@JanMarvin
JanMarvin / pivot_table_choose.R
Created November 30, 2023 19:58
Pivot table example from LinkedIn
library(openxlsx2)
packageVersion("openxlsx2")
wb <- wb_workbook() %>%
wb_add_worksheet("table") %>%
wb_add_worksheet("data") %>%
wb_add_data(x = datasets::esoph)
df <- wb_data(wb)
library(openxlsx2)
if(exists("df_tmp")) {rm(df_tmp)}
a <- c("Above & Beyond", "Fully Met", "Partially Met", "Did Not Meet") # try using "&" instead of "and"
b <- c(.15, .70, .10, .05);
c <- c("","","","")
d <- c("","","","")
e <- c("","","","")
f <- c("","","","")
df_tmp <- data.frame(a,b,c,d,e,f)
@JanMarvin
JanMarvin / Working_with_openxlsx2.R
Created August 27, 2023 11:47
Working with {openxlsx2}
#
# openxlsx2 implementation of
# https://layalchristinelettry.rbind.io/blog/202303_openxlsx/
#
#### helper function -----------------------------------------------------------
prepare_penguins_mod <- function(data,
data_raw) {
# for demonstration purposes, add a column "any_comment" and "size"
data |>
@JanMarvin
JanMarvin / flextable_fancy.R
Last active August 12, 2023 16:36
flextable fancy footer
library(openxlsx2) # github with #496 for all tables
library(flextable)
### wrapper function to add flextable objects to openxlsx2 worksheets
wb_add_flextable <- function(wb, sheet = current_sheet(), ft) {
# get all rows to merge
merge_rows <- function(ft_part, part_rows) {
rows <- ft_part$spans$rows
@JanMarvin
JanMarvin / pivot_table_sort.R
Created June 27, 2023 18:35
pivot-table sort
library(openxlsx2)
# example code
df<- tibble::tribble(
~Plant, ~Location, ~Status, ~Units,
"A", "E", "good", 0.95,
"C", "F", "good", 0.95,
"C", "E", "good", 0.95,
"B", "E", "good", 0.95,
"B", "F", "good", 0.89,
@JanMarvin
JanMarvin / R_lib_w_onedrive.R
Last active November 26, 2021 12:41
R with onedrive
# rundll32 sysdm.cpl,EditEnvironmentVariables
# add new: R_USER C:/Users/<username>
Sys.getenv("R_USER")
Sys.getenv("R_LIBS_USER")
@JanMarvin
JanMarvin / Exchage_Rates.R
Created February 21, 2021 20:37
Exchange rates GBP, EUR and USD
library(reshape2)
library(ragg)
library(ggplot2)
# devtools::install_github("opensdmx/rsdmx")
library(rsdmx)
usd_eur <- readSDMX("https://sdw-wsrest.ecb.europa.eu/service/data/EXR/D.USD.EUR.SP00.A")
usd_eur <- as.data.frame(usd_eur)
usd_eur <- usd_eur[c("obsTime", "obsValue")]
@JanMarvin
JanMarvin / PKGBUILD
Last active January 24, 2021 22:11
soci PKGBUILD
# Maintainer: Marcin (CTRL) Wieczorek <marcin@marcin.co>
# Contributor: Daniel Nagy <danielnagy at gmx de>
# Contributor: Mika Fischer <mika.fischer@zoopnet.de>
pkgname=soci
pkgver=4.0.1
pkgrel=4
pkgdesc="Database access library for C++"
arch=('i686' 'x86_64')
url="http://soci.sf.net"