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
| # It overcomes the weakness of data.table's melt() | |
| # when using measure.vars=patterns(multiple regex patterns), | |
| # which results in a new column (named with variable.name) | |
| # holding column indexes instead of the | |
| # substrings extracted with the regex patterns. | |
| library(data.table) | |
| library(magrittr) | |
| meltMultipleCols <- function(dt, |
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
| ### Usage example 1 -- not reshaped: | |
| # > my_url <- 'https://webgate.ec.europa.eu/fastop/wq/ameco/online?fullVariable=3.0.0.0.ZEKND&countries=AUT,BEL,BGR,CYP,CZE,DEU,DNK,EA19,EA20,ESP,EST,EU27,FIN,FRA,GRC,HRV,HUN,IRL,ITA,LTU,LUX,LVA,MLT,NLD,POL,PRT,ROM,SVK,SVN,SWE&years=1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026&lastYear=1&yearOrder=DESC' | |
| # > x <- importDataFromAMECOLink(my_url, variables_to_columns=FALSE) | |
| # > str(x) | |
| # Classes ‘data.table’ and 'data.frame': 1972 obs. of 7 variables: | |
| # $ Country: chr "Austria" "Austria" "Austria" "Austria" ... | |
| # $ CNTRY : chr "AUT" "AUT" "AUT" "AUT" ... | |
| # $ geo : chr "AT" "AT" "AT" "AT" ... | |
| # $ Label : chr "Capital-labour substitution: total economy" "Capital-labour sub |
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(shiny) | |
| library(DT) | |
| library(shinycssloaders) | |
| library(magrittr) | |
| library(data.table) | |
| library(eurodata) | |
| ui <- fluidPage( | |
| titlePanel(HTML(paste0('<a href="https://ec.europa.eu/eurostat/api/dissemination/catalogue/metabase.txt.gz?labels=no"', | |
| 'target="_blank">Eurostat Metabase</a> 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
| // Conversion of missing values doesn't work!!! -- to be corrected | |
| use extendr_api::prelude::*; | |
| use umya_spreadsheet::*; | |
| use umya_spreadsheet::writer::xlsx; | |
| #[extendr] | |
| fn save_dataframe_to_excel(df: Robj, file_path: &str) -> extendr_api::Result<()> { | |
| // Ensure the input is a DataFrame | |
| let dataframe = df |
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 |
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::*; | |
| #[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
| 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
| # 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
| renameColumns <- function(dt, ...) { | |
| pairs <- | |
| substitute(list(...)) %>% | |
| as.list %>% | |
| tail(-1) %>% | |
| lapply(. %>% as.list %>% tail(-1) %>% rev) | |
| from <- | |
| pairs %>% | |
| sapply(. %>% .[[1]] %>% as.character) | |
| to <- |