4

In continuation of my unsolved post, I have altered my requirement to writing a file (.jpeg in this specific example) to OneDrive with the help of R Script.


#Loading required packages 
library(outbreaks)
library(incidence)
library(RCurl)

#Data transformation
cases = subset(nipah_malaysia, select = c("perak", "negeri_sembilan", "selangor",
                                          "singapore"))

i = as.incidence(cases, dates = nipah_malaysia$date, interval = 7L)

#Saving to the local working directory
jpeg(plot.jpeg)

#Trying to upload using an absolute path. However, doesn't work.
#jpeg(file = "https://1drv.ms/u/s!AtWMPT_CT0l3hB6flgne1OHU34SV?e=3zAJfL/plot.jpg")

plot(i)
dev.off()

Created on 2020-07-17 by the reprex package (v0.3.0)

Below is the error when I use OneDrive's absolute path (I've used personal account for testing. But, an organization's account is used in real-time.)

Error:

Error in jpeg(file = "https://1drv.ms/u/s!AtWMPT_CT0l3hB6flgne1OHU34SV?e=3zAJfL/plot.jpg") : 
  unable to start jpeg() device
In addition: Warning messages:
1: In jpeg(file = "https://1drv.ms/u/s!AtWMPT_CT0l3hB6flgne1OHU34SV?e=3zAJfL/plot.jpg") :
  unable to open file 'https://1drv.ms/u/s!AtWMPT_CT0l3hB6flgne1OHU34SV?e=3zAJfL/plot.jpg' for writing
2: In jpeg(file = "https://1drv.ms/u/s!AtWMPT_CT0l3hB6flgne1OHU34SV?e=3zAJfL/plot.jpg") :
  opening device failed

Of course, from the error, I understood that uploading is not so straight forward. I did some research and came across a few articles such as:

  1. https://community.powerbi.com/t5/Service/R-script-Write-to-csv-file-on-Onedrive/td-p/487374
  2. Cannot write csv file on a secured OneDrive folder using R script in Power BI without OneDrive API

I learnt that an API needs to be established with OneDrive using R Script but I'm uncertain in accomplishing the task. I did find the OneDrive API for uploading small files.

Any guidance or suggestions in implementing the OneDrive API using R would be highly appreciated.

1 Answers1

1

The Microsoft365R package is dedicated to this kind of task. Specifically, you probably want to read the vignette on OneDrive and the one for authentication.

Tripartio
  • 1,955
  • 1
  • 24
  • 29