| # Install required packages if not already installed | |
| if (!requireNamespace("arrow", quietly = TRUE)) { | |
| install.packages("arrow") | |
| } | |
| if (!requireNamespace("data.table", quietly = TRUE)) { | |
| install.packages("data.table") | |
| } | |
| library(arrow) | |
| library(data.table) | |
| # URL of the CSV file | |
| #url <- "https://huggingface.co/datasets/cjerzak/LinkOrgs/resolve/main/PosMatches_mat.csv" | |
| url <- "https://huggingface.co/datasets/cjerzak/LinkOrgs/resolve/main/PosMatches_mat_hold.csv" | |
| # Temporary file path to save the downloaded CSV | |
| temp_file <- tempfile(fileext = ".csv") | |
| # Download the CSV file | |
| download.file(url, temp_file, mode = "wb") | |
| # Read the CSV file | |
| data <- fread(temp_file, header = TRUE) | |
| # Write the data to Parquet format, which is efficient and preferred for large datasets on Hugging Face | |
| # write_parquet(data, "~/Downloads/PosMatches_mat.parquet") | |
| # Write a sample | |
| # samp_ <- sample(1:nrow(data),1000) | |
| data <- as.data.frame(data) | |
| data <- data[,colnames(data) %in% c("name1","name2","matchProb") ] | |
| write_parquet(data, "~/Downloads/PosMatches_mat_sample.parquet") | |
| data.table::fwrite(data, "~/Downloads/PosMatches_mat_sample.csv") | |
| # Optional: Clean up temporary file | |
| unlink(temp_file) | |
| # Message | |
| cat("Data has been downloaded, processed, and saved as PosMatches_mat_sample.parquet\n") | |