This file contains hidden or 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
| # just a stub to change the title of the gist |
This file contains hidden or 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
| # Convert Excel column letter codes to numbers | |
| # Very similar to openxlsx::convertFromExcelRef() (see https://rdrr.io/cran/openxlsx/man/convertFromExcelRef.html). | |
| # The inverse function to openxlsx::int2col() (see https://rdrr.io/cran/openxlsx/man/int2col.html). | |
| # | |
| # excelColsToInt(c('a','F','x','aa','az','aaa','a','Az','aZ','AZ')) | |
| # #=> int [1:10] 1 6 24 27 52 703 1 52 52 52 | |
| # | |
| # x <- c('a','F','x','aa','az','aaa','a','Az','aZ','AZ') | |
| # n <- excelColsToInt(x) | |
| # x2 <- openxlsx::int2col(n) |
This file contains hidden or 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
| # Parse Oracle metadata SQL file obtained via "Quick DDL > Save to File..." | |
| # (see https://stackoverflow.com/a/14262027) | |
| # in Oracle SQL Developer (tested with version 19.2.1.247.2212) | |
| # into R code which builds a list of data.tables with 0 length columns | |
| # which can be later visualised via autoschema::schema -- see | |
| # the example: | |
| # r_code <- parseQDDL('exported.sql') ## the top-level function defined below | |
| # library(autoschema) ## it can be obtained from https://github.com/alekrutkowski/autoschema | |
| # schema(eval(parse(text=r_code))) ## see the graph or... |
This file contains hidden or 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(magrittr) | |
| library(data.table) | |
| summaries <- function(dt, col_names, fun_names, additional_code, by, sep='__') | |
| eval(parse( | |
| text= | |
| expand.grid(var=col_names, fun=fun_names) %>% | |
| {paste0('`',.$fun,sep,.$var,'`=`',.$fun,'`(',.$var,')')} %>% | |
| c(additional_code) %>% | |
| paste(collapse=',') %>% |
This file contains hidden or 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
| import eurostat | |
| import pandas as pd | |
| def importData(EurostatDatasetCode, flags=False): | |
| """ | |
| Import a dataset from Eurostat as a flat/melted table (pandas dataframe) | |
| Parameter | |
| ---------- | |
| EurostatDatasetCode : str |
This file contains hidden or 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
| # ## Example: ⮦ time=3 missing | |
| # library(magrittr) | |
| # data.table(time = c(1,2, 4,5,6, | |
| # 1,2), | |
| # my_x = c(11:15, | |
| # 11,12), | |
| # my_y = c(101,103,105,NA,109, | |
| # 111,121), | |
| # group = c(rep.int('a',5), | |
| # rep.int('b',2))) %>% |
This file contains hidden or 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(magrittr) | |
| monthToQuarter <- function(charvec, safe=TRUE) { | |
| # monthToQuarter(c('2022M01','2022M02','2022M03','2022M04', | |
| # NA_character_,'2022M12')) | |
| # # "2022Q1" "2022Q1" "2022Q1" "2022Q2" NA "2022Q4" | |
| if (safe) | |
| stopifnot(all(grepl('^[1-2][0-9]{3}M[0-1][0-9]', | |
| charvec) | is.na(charvec))) | |
| yr <- |
This file contains hidden or 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(magrittr) | |
| library(data.table) | |
| download.file('https://ec.europa.eu/economy_finance/db_indicators/ameco/documents/ameco0.zip', | |
| 'ameco0.zip') | |
| time_stamp <- | |
| 'https://ec.europa.eu/info/business-economy-euro/indicators-statistics/economic-databases/macro-economic-database-ameco/download-annual-data-set-macro-economic-database-ameco_en' %>% | |
| rvest::read_html() %>% | |
| rvest::html_elements(xpath='//*[@id="block-ewcms-theme-main-page-content"]/article/div/div/div/div[2]/div/div/p[1]/text()[2]') %>% | |
| rvest::html_text() %>% |
This file contains hidden or 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
| options(width=200) | |
| if (interactive()) { | |
| message('================================================================================') | |
| ab <- function(sym_as_str, fun) | |
| makeActiveBinding(sym_as_str, fun, .GlobalEnv) | |
| library(magrittr) | |
| message('- Imported package `magrittr`') | |
| library(data.table) |
This file contains hidden or 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
| main = do | |
| putStrLn $ show $ add (MyInt 1) (MyInt 3) | |
| -- MyInt 4 | |
| putStrLn $ show $ add (MyInt 13) (MyString "B") | |
| -- MyString "13B" | |
| putStrLn $ show $ add (MyString "B") (MyInt 13) | |
| -- MyString "B13" | |
| putStrLn $ show $ add (MyString "a") (MyString "b") | |
| -- MyString "ab" | |
| putStrLn $ show $ add' $ IntInt 1 3 |