I'm trying to extract some functions stored on dropbox (in a folder).
It all goes well until I try to untar the file. Here's an example:
library("R.utils")
temp <- tempfile()
temp<-paste(temp,".gz",sep="")
download.file("http://www.dropbox.com/sh/dzgrfdd18dljpj5/OyoTBMj8-v?dl=1",temp)
untar(temp,compressed="gzip",exdir=dirname(temp))
Here I get an error:
Error in rawToChar(block[seq_len(ns)]) :
embedded nul in string: 'PK\003\004\024\0\b\b\b....
Ideally I would then load all the functions in folder like this:
sourceDirectory(dirname(temp))
...but I need to be able to untar them first. I can open the archive in Windows but in R I get the error above. Can anyone help? I've tried to use unzip but this only works with smaller folders downloaded from dropbox (such as the one above), bigger ones only work as gzip format (at least in my experience).
# use the httr package
library(httr)
# define your desired file
u <- "http://www.dropbox.com/sh/dzgrfdd18dljpj5/OyoTBMj8-v?dl=1"
# save the file to a .zip
tf <- paste0( tempfile() , '.zip' )
# create a temporary directory
td <- tempdir()
# get the file
fc <- GET(u)
# write the content of the download to a binary file
writeBin(content(fc, "raw"), tf)
# unzip it.
unzip( tf , exdir = td )
# locate all files in this directory
af <- list.files( td , recursive = TRUE )
# subset the files to the ones ending with R
R.files <- af[ substr( af , nchar( af ) , nchar( af ) ) == 'R' ]
# set your working directory
setwd( td )
# source 'em
for ( i in R.files ) source( i )
# see that they're loaded
ls()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With