File size: 1,288 Bytes
baa0463 3558f7d baa0463 3558f7d baa0463 3558f7d baa0463 3558f7d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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")
|