spindoctor
spindoctor

Reputation: 1895

Loading SPSS files from github

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)

Upvotes: 1

Views: 564

Answers (1)

Cristian E. Nuno
Cristian E. Nuno

Reputation: 2920

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 # 

Upvotes: 2

Related Questions