cjerzak commited on
Commit
baa0463
·
verified ·
1 Parent(s): c4d019b

Create scripts/paraquet_conversion.R

Browse files
Files changed (1) hide show
  1. scripts/paraquet_conversion.R +40 -0
scripts/paraquet_conversion.R ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Install required packages if not already installed
2
+ if (!requireNamespace("arrow", quietly = TRUE)) {
3
+ install.packages("arrow")
4
+ }
5
+ if (!requireNamespace("data.table", quietly = TRUE)) {
6
+ install.packages("data.table")
7
+ }
8
+
9
+ library(arrow)
10
+ library(data.table)
11
+
12
+ # URL of the CSV file
13
+ url <- "https://huggingface.co/datasets/cjerzak/LinkOrgs/resolve/main/PosMatches_mat.csv"
14
+
15
+ # Temporary file path to save the downloaded CSV
16
+ temp_file <- tempfile(fileext = ".csv")
17
+
18
+ # Download the CSV file
19
+ download.file(url, temp_file, mode = "wb")
20
+
21
+ # Read the CSV file. Assuming it may not have headers, we'll add them.
22
+ # If it does have headers, set header = TRUE and skip the colnames line.
23
+ data <- fread(temp_file, header = FALSE)
24
+
25
+ # Add column names if needed (assuming 256 columns based on common structure)
26
+ if (ncol(data) == 256) {
27
+ setnames(data, paste("D", 1:256, sep = ""))
28
+ } else {
29
+ # Adjust based on actual number of columns
30
+ setnames(data, paste("V", 1:ncol(data), sep = ""))
31
+ }
32
+
33
+ # Write the data to Parquet format, which is efficient and preferred for large datasets on Hugging Face
34
+ write_parquet(data, "~/Downloads/PosMatches_mat.parquet")
35
+
36
+ # Optional: Clean up temporary file
37
+ unlink(temp_file)
38
+
39
+ # Message
40
+ cat("Data has been downloaded, processed, and saved as PosMatches_mat.parquet\n")