Get the size of a file with googledrive R package

Viewed 117

I am trying to get the size, like in kb or MB, from files allocated on my google drive using the googledrive R package. I could not find any function to get the size of a specific google id. The closest I got was something like:

library(googledrive)

my.id <- "1beivwzTeY7K51tvyJH2Jdidgb7hxCeNh" 

drive_reveal(as_id(my.id), "path")

# A tibble: 1 x 4   name                  path                                             id                  drive_resource    <chr>                 <chr>    
<chr>                <list>          1 liver_raw_snp_…Data/folder/ne_s… 1d90WkmUHHT9Ccf-OcU… <named list [3…

Is there a way to get the file size or the total folder size using googledrive R package? Something like the pseudocode below:

drive_reveal(as_id(my.id), "size") #pseudocode to get file/folder sizes
1 Answers

Yes, the API provides access to the file attribute "size", but I don't believe any of the functions in the googledrive package explicitly print it.

The only way to access it (as far as I know) is:

library(tidyverse)
#install.packages("googledrive")
library(googledrive)

my_id <- "1beivwzTeY7K51tvyJH2Jdidgb7hxCeNh"
y <- drive_reveal(as_id(my_id))
y$drive_resource[[1]]$size

To get the size of all files in a folder:

folder_id <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
x <- drive_ls(as_id(folder_id))

size <- NULL
for(i in seq_along(x$drive_resource)){
  print(x$drive_resource[[i]]$size)
  size[[i]] <- x$drive_resource[[i]]$size
}

paste(sum(as.numeric(size))/1000000, "Mb", sep = " ")
#>[1] "125.894124 Mb"
Related