TimStats commited on
Commit
522d1b9
·
verified ·
1 Parent(s): fb70766

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +36 -1
app.R CHANGED
@@ -80,7 +80,42 @@ timstuff <- function(game) {
80
  return(game_complete)
81
  }
82
 
83
- MLB24T <- read.csv("MLB24T.csv", header = TRUE, check.names = FALSE, fileEncoding = "UTF-8")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  MLB24T <- timstuff(MLB24T)
86
 
 
80
  return(game_complete)
81
  }
82
 
83
+ download_private_parquet <- function(repo_id, filename) {
84
+ library(httr)
85
+ library(arrow)
86
+
87
+ # Create the direct download URL based on your example
88
+ url <- paste0("https://huggingface.co/datasets/", repo_id, "/resolve/main/", filename, "?download=true")
89
+
90
+ # Create a temporary file
91
+ temp_file <- tempfile(fileext = ".parquet")
92
+
93
+ # Download directly to file
94
+ response <- GET(
95
+ url,
96
+ add_headers(Authorization = paste("Bearer", Sys.getenv("GETCSV"))),
97
+ write_disk(temp_file, overwrite = TRUE)
98
+ )
99
+
100
+ # Check if download was successful
101
+ if (status_code(response) == 200) {
102
+ tryCatch({
103
+ # Read the parquet file
104
+ data <- read_parquet(temp_file)
105
+ file.remove(temp_file)
106
+ return(data)
107
+ }, error = function(e) {
108
+ file.remove(temp_file)
109
+ stop(paste("Error reading parquet file:", e$message))
110
+ })
111
+ } else {
112
+ file.remove(temp_file)
113
+ stop(paste("Failed to download file. Status code:", status_code(response)))
114
+ }
115
+ }
116
+
117
+
118
+ MLB24 <- download_private_parquet("TimStats/StatcastDataAll", "MLB26.parquet")
119
 
120
  MLB24T <- timstuff(MLB24T)
121