Skip to content

Instantly share code, notes, and snippets.

View SchmidtPaul's full-sized avatar
😏

Paul Schmidt SchmidtPaul

😏
View GitHub Profile
Chapter 1: R Intro
https://schmidtpaul.github.io/dsfair_quarto/rbasics/firststeps.html
Chapter 2: Tidyverse
https://schmidtpaul.github.io/dsfair_quarto/rbasics/tidyverse.html
Chapter 3: Correlation & Regression
https://schmidtpaul.github.io/dsfair_quarto/rbasics/correlation_regression.html
Chapter 4: Bad Data & Outlier
@SchmidtPaul
SchmidtPaul / mycustomprompts.json
Last active March 13, 2024 08:18
Prompts used via slash commands in ChatGPT Desktop Application
[
{
"cmd": "Py",
"act": "Python Code Assistant",
"prompt": "You are my Python Code Assistant. Whenever you help me with Python code, I want the following things: Never tell me to or show me how to install and/or load a module. Instead, skip right to the actual code. 2. Never reproduce a array/dataframe etc. that I pasted unless I explicitly ask you to. Instead, skip right to the actual code where you can refer to any of my arrays/dataframes either with their name or - if no name was provided - with dummy names like `your_array`. 3. Make use of numpy, pandas and piping. 4. I dont care whether you actually run python code or not, however the answer must always be Python code which I can easily copy-paste 5. Always immediately start with the code. Any additional explanations should be written at the very end of your response.",
"enable": true
},
{
"cmd": "R",
"act": "R Code Assistant",
@SchmidtPaul
SchmidtPaul / ChatGPT_R_assistant_initial_prompt.txt
Last active July 21, 2023 08:10
ChatGPT R assistant initial prompt
You are my R Code Assistant. Whenever you help me with R code, I want the following things: 1. Never tell me to or show me how to install and/or load a package. Instead, skip right to the actual code. 2. Never reproduce a table/vector etc. that I pasted unless I explicitly ask you to. Instead, skip right to the actual code where you can refer to any of my tables/vectors either with their name or - if no name was provided - with dummy names like `your_table`. 3. Make use of the tidyverse and pipes (%>%). If applicable and advantageous, also make use of {lubridate}, {purrr} and/or {scales}. 4. Always immediately start with the code. Any additional explanations should be written at the very end of your response.
@SchmidtPaul
SchmidtPaul / SAS in RMarkdown.Rmd
Last active July 27, 2022 07:42
Execute SAS Code from within an RMarkdown file
---
title: "Run SAS in R"
author: Dr. Paul Schmidt, BioMath GmbH
output: word_document
---
```{r, include = FALSE}
library(SASmarkdown)
knitr::opts_chunk$set(
engine = "sas",
@SchmidtPaul
SchmidtPaul / get_title_landscape.R
Last active March 16, 2022 15:35
Create title landscape image
# inspiration: https://albert-rapp.de/post/2021-12-31-ggforce-examples/
library(ggforce)
library(tidyverse)
set.seed(42)
tibble(x = runif(1000), y = runif(1000)) %>%
ggplot(aes(x, y)) +
geom_voronoi_tile(aes(fill = y)) +
@SchmidtPaul
SchmidtPaul / ggplot2_labelsleftandright.R
Last active February 21, 2022 09:38
ggplot2: Positioning labels (or other geoms) on the outter sides when I only have two levels on my x-axis
library(tidyverse)
# data --------------------------------------------------------------------
dat <- tibble(
x = c("A", "A", "B", "B"),
y = c(12, 11, 13.03, 13),
grp = c("G1", "G2", "G1", "G2"),
lab = c("a", "abc", "ab", "abcd")
) %>%
mutate_if(is.character, as.factor)
@SchmidtPaul
SchmidtPaul / Change_ggplot_fonts.R
Created December 16, 2021 21:27
Use different fonts in ggplot2
# taken from youtube tutorial: https://youtu.be/hPTBZelmAh4
library(showtext)
library(ggplot2)
font_add(family = "ComicSansMS", regular = "Comic.ttf")
showtext_auto()
labeldata <- data.frame(mylabel = "geom_text font\nmust be changed\nseparately like this",
group = 1.5,
@SchmidtPaul
SchmidtPaul / formatted_desc_table_2way.R
Last active November 25, 2021 14:46
Get formatted descriptive table for numeric variable grouped by two categorical variables
library(dlookr)
library(tidyverse)
dat <- mtcars %>%
transmute(Cyl = as.factor(cyl),
Am = as.factor(am),
hp = hp)
bind_rows(
dat %>% describe(hp),
@SchmidtPaul
SchmidtPaul / RunningRinSAS.sas
Last active November 11, 2021 17:11
Run R-Code in SAS
/*******************************************************************************************************/
/* First time setup: */
/* You must take one manual step before your SAS can run R-Code: Edit the SAS-config-file (sasv9.cfg). */
/* To locate this file on your PC, you can run the following code in SAS and it will return the */
/* path to the SAS-config-file in the log: */
/* proc options option=config; run; */
/* It will possibly be: C:\Program Files\SASHome\SASFoundation\9.4\nls\en\sasv9.cfg */
/* Find that file and edit it as shown in this video at 1:10min (i.e. add '-RLANG') */
/* https://www.youtube.com/watch?v=3pbXUthE1As&t=110s */
/* If Windows does not allow you to save/overwrite the file after edi
@SchmidtPaul
SchmidtPaul / gg_export()
Last active April 4, 2022 13:43
It's basically ggsave() with some addons
# This function exports plots. It always creates a pdf and can additionally
# create png files (defaults: create_png = TRUE; ). You provide the
# folder_path and the file_name and by default both folder_path/file_name.pdf
# and folder_path/file_name.png will be created.
#
# You may immediately preview the created files by automatically having them
# opened on your computer after being created (defaults: open_pdf = FALSE;
# open_png = TRUE).
#
# The pdf is exported via ggplot2::ggsave(), but the png is not! Instead,