Skip to content

Utility to immediately provide shareable link to data #233

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
alexpghayes opened this issue Oct 10, 2018 · 7 comments
Open

Utility to immediately provide shareable link to data #233

alexpghayes opened this issue Oct 10, 2018 · 7 comments
Labels
feature a feature request or enhancement future [up|down]load ⬆️ ⬇️

Comments

@alexpghayes
Copy link

I've been using the following for a little while to quickly share small datasets via Google Drive.

Would love to submit a PR, not sure about the best final form for this:

# upload a data frame to google drive, make it shareable, and
# copy the shareable link into the clipboard
get_shareable_link_to_data <- function(data, path, direct = TRUE) {
  readr::write_csv(data, path)
  df <- googledrive::drive_upload(path, path)
  df <- googledrive::drive_share(df, role = "reader", type = "anyone")

  if (direct)
    link <- paste0("https://drive.google.com/uc?export=download&id=", df$id)
  else
    link <- googledrive::drive_link(df)

  clipr::write_clip(link)
  fs::file_delete(path)
  cat(link)
  invisible(link)
}

When direct = TRUE, the link can be immediately used in read_csv(). When direct = FALSE, the link send users to the Google Drive preview of the data.

@jennybc
Copy link
Member

jennybc commented Oct 10, 2018

Good idea!

I think it would be interesting to hash this out in the company of:

#44 Uploading an R object w/o writing to file
#81 drive_read()?

The common theme seems to be "local data frame" <--> "csv on Google Drive" and making the intermediate local file fade into the background or be unnecessary.

@alexpghayes
Copy link
Author

I don't know enough about googledrive to understand what's most idiomatic here. Any guidance?

More than anything the takeaway that I want is a link that I can copy-paste directly into a chat, email or Github issue to avoid the hassle of figuring out how to actually upload a data frame somewhere.

Might also be worth uploading files to a /.auto_uploads/ folder or similar. In my experimentation, it was pretty easy to accidentally fill my main Drive folder with tons of garbage / redundant data sets.

@jennybc
Copy link
Member

jennybc commented Oct 11, 2018

Did you have trouble with uploading multiple things with the same name? Drive lets you do that.

@alexpghayes
Copy link
Author

No trouble with multiple uploads. I have like 28 copies of mtcars.csv in my Drive right now.

@jennybc
Copy link
Member

jennybc commented Oct 11, 2018

Yeah I meant ... are you unhappy with that situation?

In #230 (Consistent naming and overwrite for drive_upload), there is a discussion about workflow when user wants to upload to a file path that already exists. Right now, we cheerfully and silently upload a new file with a replicated name, because that's how Drive works.

But most people don't mean to do this and it makes it hard for them to distinguish their 28 files with the same name but potentially different contents.

This will come up here too.

@alexpghayes
Copy link
Author

Ah, gotcha. What about an option overwrite that defaults to TRUE?

Then if overwrite = TRUE and path = "mtcars.csv", but there are already 2+ files names mtcars.csv, give an informative error, since it won't be clear which file to overwrite.

@jennybc jennybc added [up|down]load ⬆️ ⬇️ feature a feature request or enhancement labels Apr 26, 2019
@jennybc jennybc added the future label Aug 15, 2019
@simonpcouch
Copy link

Not at all a comprehensive solution, but I put together a package this morning to address part of the "local data frame" <--> "csv on Google Drive" workflow that @jennybc and Issue #81 mentioned. This package supplies a grab_data function that is a wrapper around drive_download and some tempfile pushings-around that takes in a URL to a .csv, .Rda, or Google Sheets file and outputs a tibble!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
feature a feature request or enhancement future [up|down]load ⬆️ ⬇️
Projects
None yet
Development

No branches or pull requests

3 participants