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
| `%not in%` <- Negate(`%in%`) | |
| `%without%` <- setdiff | |
| `%++%` <- paste0 | |
| `%is%` <- inherits | |
| `%equals%` <- identical |
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
| webR.download.file <- function(url, destfile) | |
| download.file(paste0("https://corsproxy.io/?",URLencode(url)), | |
| destfile) | |
| # See https://github.com/r-wasm/webr/issues/252#issuecomment-1690142510 |
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
| namedList <- function(...) { | |
| # Capture the variable names as symbols | |
| # and convert symbols to character names | |
| var_names <- as.character(as.list(substitute(list(...)))[-1]) | |
| # Create a named list | |
| stats::setNames(mget(var_names, envir = parent.frame()), var_names) | |
| } | |
| ### Usage example |
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) | |
| setnamesWithArrows <- function(dt, ...) { | |
| pairs <- | |
| substitute(list(...)) %>% | |
| as.list %>% | |
| tail(-1) %>% | |
| lapply(. %>% as.list %>% tail(-1) %>% rev) | |
| from <- |
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
| renameColumns <- function(dt, ...) { | |
| pairs <- | |
| substitute(list(...)) %>% | |
| as.list %>% | |
| tail(-1) %>% | |
| lapply(. %>% as.list %>% tail(-1) %>% rev) | |
| from <- | |
| pairs %>% | |
| sapply(. %>% .[[1]] %>% as.character) | |
| to <- |
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
| # Code generated with eurodata_codegen on 2024-09-18 16:26:27 (UTC+2:00, Central European Summer Time) | |
| library(magrittr) | |
| library(data.table) | |
| library(eurodata) | |
| library(openxlsx2) | |
| dt__lfsi_emp_a <- | |
| ## Link to filtered raw data (TSV): | |
| # https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/LFSI_EMP_A/.EMP_LFS.T.Y20-64.PC_POP.EU27_2020?format=TSV | |
| ## Meaning of the codes in `filters` below: |
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
| let | |
| Source = Csv.Document(Web.Contents("https://ec.europa.eu/eurostat/api/dissemination/sdmx/3.0/data/dataflow/ESTAT" & | |
| "/nama_10_gdp/1.0/*?" & // ← modify dataset | |
| // ↓ modify dimensions and their values | |
| "c[unit]=CP_MEUR&c[na_item]=B1GQ,P3&c[geo]=EU27_2020,EA20" & | |
| "&compress=false&format=csvdata&formatVersion=2.0&" & | |
| "c[TIME_PERIOD]=ge:2021+le:2023"), // ← modify time span | |
| [Delimiter=",", | |
| Encoding=65001, QuoteStyle=QuoteStyle.None]), | |
| PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars=true]), |
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
| use extendr_api::prelude::*; | |
| #[extendr] | |
| fn transpose_char_matrix(matrix: RMatrix<Rstr>) -> Robj { | |
| // Take the input dimensions | |
| let dims = matrix.dim(); | |
| // Get the number of rows and columns | |
| let nrows = dims[0] as usize; | |
| let ncols = dims[1] as usize; |
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
| use extendr_api::prelude::*; | |
| use rand::{distributions::Alphanumeric, Rng}; | |
| use std::collections::HashMap; | |
| // Define the function to be used in R | |
| #[extendr] | |
| fn add_columns(df: Dataframe<Robj>) -> List { | |
| // Get the number of rows in the data frame | |
| let n_rows = df.get_attrib("row.names").unwrap().len(); |
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
| use extendr_api::prelude::*; | |
| use polars::prelude::*; | |
| // Helper function to convert an R data.frame to a Polars DataFrame | |
| fn r_to_polars_dataframe(r_df: List) -> Result<DataFrame> { | |
| let mut columns = Vec::new(); | |
| for (name, col) in r_df.iter() { | |
| let col_name: PlSmallStr = name.into(); // Convert column name to PlSmallStr |