3

Although this response seems to be a bit relevant (using a package), I'm wondering how I can use R BASE to import a csv file using a shareable google drive link into R studio?

There are two columns in my csv file and two column names (namely "dd" and "yy"). But no row.names.

Presently, I'm trying the following R code (with no success):

 myurl <- "https://drive.google.com/file/d/0B5V8AyEFBTmXM1VIYUYxSG5tSjQ/view?usp=sharing"


read.csv(url(myurl), header = T, row.names = F)

The error I'm getting is:

Error in read.table(file = file, header = header, sep = sep, quote = quote, : more columns than column names

Community
  • 1
  • 1
rnorouzian
  • 7,397
  • 5
  • 27
  • 72

1 Answers1

7

The answer was indicated in the post you linked. Namely,

id <- "0B5V8AyEFBTmXM1VIYUYxSG5tSjQ"
stuff <- read.csv(sprintf("https://docs.google.com/uc?id=%s&export=download", id))
Jeff Yontz
  • 246
  • 1
  • 10
  • Nah, sprintf is something you probably haven't seen before if you've never done C programming. Basically you have a wildcard `%s` that says there's going to be a string variable after this that I want you to put here. A more conventional "R" approach to it would be: `read.csv(paste0("https://docs.google.com/uc?id=",id,"&export=download")) ` – Jeff Yontz Feb 25 '17 at 21:50
  • Wow, so this also works for an .R file shared with someone and than that person can `source()` the shareable google drive link and run your .R from a distance? – rnorouzian Feb 25 '17 at 21:58
  • That is correct as long as the correct permissions are set up on the Google Sheet. For this sheet, it should be since I was able to view it. – Jeff Yontz Feb 25 '17 at 22:17