1

I don't understand how to import SPSS files (or .rdata or Stata) files that are hosted on github. I have a repository with some data files here, but using the URL for the sav file in there does not work.

library(haven)
ces<-'https://github.com/sjkiss/CES2015/CES2015-phone-release/CES2015_CPS-PES-MBS_complete.sav'
out<-read_sav(ces)
zx8754
  • 42,109
  • 10
  • 93
  • 154
spindoctor
  • 1,359
  • 1
  • 11
  • 27
  • 2
    You need to use the raw file address from Github. This file seems to be here (didn't try loading it): [https://github.com/sjkiss/CES2015/raw/master/CES2015-phone-release/CES2015_CPS-PES-MBS_complete.sav](https://github.com/sjkiss/CES2015/raw/master/CES2015-phone-release/CES2015_CPS-PES-MBS_complete.sav) . In general, you can click on the "Find file" tab in the Github explorer. – David Klotz Feb 12 '18 at 21:46

1 Answers1

2

Overview

As @DavidKlotz commented in the OP, you need to copy the URL of the file of interest; not the URL of the page that hosts the file of interest on GitHub.

Copy the URL from either the Download button, as shown below, or from the View Raw hyperlink and paste it into the file argument within the haven::read_sav() function in .

SS of GitHub

# load necessary package
library( haven )

# transform GitHub url
# from 'Download' button
# into data frame
df <- read_sav( file = "https://github.com/sjkiss/CES2015/raw/master/CES2015-phone-release/CES2015_CPS-PES-MBS_complete.sav" )

# view the dimensions
dim( df ) # [1] 4202  454

# transform GitHub url
# from 'View Raw' hyperlink
# into data frame
df <- read_sav( file = "https://github.com/sjkiss/CES2015/blob/master/CES2015-phone-release/CES2015_CPS-PES-MBS_complete.sav?raw=true" )

# view the dimensions
dim( df ) # [1] 4202  454

# end of script # 
Cristian E. Nuno
  • 2,442
  • 2
  • 12
  • 28