简体   繁体   中英

source_data R from private repository

I am trying to read one RData file from my private repository "data" in R

library(repmis)

source_data("https://github.com/**********.Rdata?raw=true") 

This is my output

Error in download_data_intern(url = url, sha1 = sha1, temp_file = temp_file) : 
  Not Found (HTTP 404). 

Other way

script <-
  GET(
    url = "https://api.github.com/repos/***/data/contents/01-wrangle-data-covid-ssa-mx-county.R",
    authenticate(Sys.getenv("GITHUB_PAT"), ""),     # Instead of PAT, could use password
    accept("application/vnd.github.v3.raw")
  ) %>%
  content(as = "text")

# Evaluate and parse to global environment
eval(parse(text = script))

Anyone knows how can I read this data from my private repo in R?

I could solve this.

  1. Generate on GitHub your personal token
    1.1 Go to GitHub
    2.1 In the right corner go to "Settings"
    2.2 Then in the left part go to "Developer setting"
    2.3 Select the option "Personal access tokens"
    2.4 Select the option "Generate new token"
    2.5 Copy your personal token
  2. On your home directory follow the next steps
    2.1 Create the file.Renviron
macbook@user:~$ touch .Reviron

On this file write your personal token like this:

macbook@user:~$ nano .Reviron
GITHUB_PAT=YOUR PERSONAL TOKEN
  1. Now on R, you can check if your personal token has been saved with this:
Sys.getenv("GITHUB_PAT")

also you can edit your token on R with this:

usethis::edit_r_environ()

Don´t forget to restart R to save your changes.

3. Finally on R these are the line codes that will load your data from private repos

library(httr)

req <- content(GET(
  "https://api.github.com/repos/you_group/your_repository/contents/your_path_to your_doc/df_test.Rdata",
  add_headers(Authorization = "token YOUR_TOKEN")
), as = "parsed")

tmp <- tempfile()
r1 <- GET(req$download_url, write_disk(tmp))
load(tmp)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM