Skip to content

Instantly share code, notes, and snippets.

View grayskripko's full-sized avatar
🏠
Working from home

Gray grayskripko

🏠
Working from home
  • Buenos Aires, Argentina
View GitHub Profile
@grayskripko
grayskripko / pandas_pipe.txt
Created February 15, 2022 10:51
Pandas .pipe() .apply() .transform() .map()
def inve(x):
print(type(x), x)
s = pd.Series([1,2,3])
s.pipe(inve) # series
s.apply(inve) # int 1
s.transform(inve) # int 1
s.map(inve) # int 1
@grayskripko
grayskripko / mutate_pmap.txt
Created December 23, 2019 09:31
mutate purrr::pmap
tibble(a=1:3, b=2:4) %>% mutate(c = pmap_dbl(., ~.x + .y))
suppressPackageStartupMessages(library(tidyverse))
tibble(a=1:3, b=2:4, c=3:5) %>% mutate(c = pmap_dbl(list(a, b, c), ~.x + .y + ..3))
#> # A tibble: 3 x 3
#> a b c
#> <int> <int> <dbl>
#> 1 1 2 6
#> 2 2 3 9
#> 3 3 4 12
foo <- function() {
a <- 1
b <- 2
quos(a, b) %>% map(as_label) %>% set_names() %>% map(get)
}
debug(remotes:::github_DESCRIPTION)
# do you really need install_github? Create a new project?
$dir = "C:\"
Set-Location $dir
$urlR = "https://cran.r-project.org/bin/windows/base/old/3.5.1/R-3.5.1-win.exe"
$outputR = "$dir\R-win.exe"
$wcR = New-Object System.Net.WebClient
$wcR.DownloadFile($urlR, $outputR)
Write-Output "Download completed"
Start-Process -FilePath $outputR -ArgumentList "/S /v/qn /VERYSILENT" -Wait
@grayskripko
grayskripko / dsvm-template.json
Last active May 24, 2019 14:17
dsvm-template
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"numberOfInstances": {
"type": "string",
"metadata": {
"description": "Number of VMs to deploy."
}
},
@grayskripko
grayskripko / 4_basic_binary_transforms_correlation.R
Last active March 9, 2019 13:41
4 basic binary transforms correlation
# we have 2 positive normal distributed features
rnorm20 <- purrr::partial(rnorm, mean = 20)
a <- rnorm20(1e5) %>% pmax(0.01) # they are positive
b <- rnorm20(1e5) %>% pmax(0.01)
# we produce 4 interactions with "opers"
opers <- c("+", "-", "/", "*")
# What are the correlations between them?
@grayskripko
grayskripko / partial_vs_docall.R
Created February 5, 2019 14:36
partial() vs do.call()
# now it works!
mean_cust <- function(...) partial(mean, !!!list(...))
mean_cust(na.rm = T)(c(1:3, NA))
# >[1] 2
@grayskripko
grayskripko / tidyverse_transpose.R
Last active February 5, 2019 14:34
tidyverse transpose
# see also https://community.rstudio.com/t/mutate-for-rows/23111
df_with_one_dtype %>%
rownames_to_column() %>%
gather(var, value, -rowname) %>%
spread(rowname, value)
@grayskripko
grayskripko / reorder_columns_tidyverse.R
Created December 23, 2018 23:05
Reorder columns #tidyverse
tibble(a = 1, b = 2) %>%
mutate(c = 3) %>%
select(1:(one_of("b") - 1), last_col(), everything()) # a c b