Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jbkunst/jbkmisc

No description or website will be provided. A collection of raw shortcuts for my daily lies.
https://github.com/jbkunst/jbkmisc

mineonlymine miscellaneous package r

Last synced: about 1 month ago
JSON representation

No description or website will be provided. A collection of raw shortcuts for my daily lies.

Awesome Lists containing this project

README

        

---
title: "jbkmisc"
output:
github_document:
toc: true
editor_options:
chunk_output_type: console
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
library(jbkmisc)
library(printr)
library(lubridate)
```

## Why? What?

Idk:

- Just things I need sometimes.
- Just helpers and wrappers for my __laziness__.

## Installation

```
source("https://install-github.me/jbkunst/jbkmisc")
```

## Date helpers

### `ym_to_date`
```{r}
ym_to_date(ym = c(200902, 201912), day = 1)
```

### `ym_diff`

```{r}
ym_diff(ym = c(200902, 201912), ym2 = c(200901, 201712))
```

### `ym_add_months`

```{r}
ym_add_months(c(200902, 201912), months = c(1, -12))
```

### `ym_format`

```{r}
ym_format(c(200902, 201912), "%B del %Y")
```

### `ym_div`

```{r}
year <- format(ymd(20170101) + months(0:11), "%Y%m")
year

ym_div(year, ng = 3)

ym_div(year, ng = 4)
```

## dplyr

### `countp`

```{r}
countp(mtcars, cyl)

countp(mtcars, cyl, am)

library(dplyr)

mtcars %>%
group_by(cyl) %>%
countp(am)
```

### `ccount`
```{r}
ccount(iris, Species)
```

### `clean`

```{r}
head(iris, 3)

clean(head(iris, 3))
```

## dbplyr

### `dbRemoveTableIfExists`
```
dbRemoveTableIfExists(con, name)
```

### `compute2`

```
compute2(con, name)
```

## ggplot2

### `theme_jbk`

Based on `hrbrthemes::theme_ipsum`, soft gridline color, legend at top for more horizontal space.

```{r}
library(ggplot2)
library(dplyr)

data("diamonds")
d <- diamonds %>%
filter(color %in% c("E", "J", "H")) %>%
filter(cut %in% c("Ideal", "Premium", "Very Good")) %>%
sample_n(10000)
theme_set(theme_jbk())

ggplot(d, aes(carat, price)) +
geom_point(aes(color = clarity), size = 0.1) +
scale_y_continuous(labels = scales::dollar) +
scale_color_viridis_d() +
facet_grid(cut ~ color, scales = "free") +
labs(
title = "This is a Title",
subtutle = "This is a longer subtitle",
caption = "A caption which nobody read but it looks important"
)
```

### `ggsav` and `filename_gen`

Automatic generation file names given a pattern to save without worry about names :D.

## blog & presentations

### `spin_jekyll_post`

My custom spin r file to md and move the widgets, etc.

### `blog_set_chunk`

Set opt chunk with my preferences

### `giphy`

Put a giphy image given the id.

### `ico`

```{r}
ico("tv", "red")
R()
```

## tictoc

```{r}
jbk_tictoc_clear()

jbk_tic(msg = "Some sleep")

Sys.sleep(2)

jbk_toc()

jbk_tic(msg = "Go to sleep again!")

Sys.sleep(1)

jbk_toc()

jbk_tictoc_log()
```

## shiny

### `get_my_local_ip`

```{r}
get_my_local_ip()
```

## Report Helpers

### `format_tbl`

```{r}
data <- data.frame(
a_value.e = c(NA, runif(3)),
`another.vAlue__here` = c(NA, runif(3)) * 10000
)

data

format_tbl(data)

format_tbl(data, digits = 0, NA_symbol = "***", fun_title = toupper)
```

## Stringr

### `str_clean`

```{r}
string <- c("name.with...points", "or_Under___scores")
string

str_clean(string)
str_clean(string, fun = toupper)
```

## Workflow

### `wf_create_folders`

create `data`, `code` and `output` folder.