Directly loading .RData from github
The problem is not in your code, it should work fine.
This, for example, loads an Rdata file from github normally
load(url("https://github.com/mawp/spict/raw/master/spict/data/pol.rda"))
Your problem comes from the files you are trying to open, they are saved with the serialization format 3 that was introduced in R version 3.5, using save(version = 3)
R has new serialization format (version 3) which supports custom serialization of ALTREP framework objects. These objects can still be serialized in format 2, but less efficiently. Serialization format 3 also records the current native encoding of unflagged strings and converts them when de-serialized in R running under different native encoding. Format 3 comes with new serialization magic numbers (RDA3, RDB3, RDX3). Format 3 can be selected by version = 3 in save(), serialize() and saveRDS(), but format 2 remains the default for all serialization and saving of the workspace. Serialized data in format 3 cannot be read by versions of R prior to version 3.5.0.
EDIT
After some more research I think it is a bug (or a feature ?).
For files saved with compression
argument equal to FALSE
, TRUE
or gz
the code works as expected in R version >= 3.5. But for compression equal to xz
which seems to be your case it does not work.
There are two options: either save the files with gz compression, or use the workaround from @user113156's answer.
Read a CSV from github into R
Try this:
library(RCurl)
x <- getURL("https://raw.github.com/aronlindberg/latent_growth_classes/master/LGC_data.csv")
y <- read.csv(text = x)
You have two problems:
- You're not linking to the "raw" text file, but Github's display version (visit the URL for https:\raw.github.com....csv to see the difference between the raw version and the display version).
- https is a problem for R in many cases, so you need to use a package like
RCurl
to get around it. In some cases (not with Github, though) you can simply replace https with http and things work out, so you can always try that out first, but I find using RCurl reliable and not too much extra typing.
Import RDS file from github into R Windows
In 2nd method you just need to add method="curl"
and also change the url to point to raw
(Download link on the page)
githubURL <- ("https://raw.githubusercontent.com/derek-corcoran-barrios/LastBat/master/best2.My.Lu2.rds")
download.file(githubURL,"best2.My.Lu2.rds", method="curl")
BestMyyu <- readRDS("best2.My.Lu2.rds")
If you don't have curl
installed, you can get it from here
Loading SPSS files from github
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 r.
# 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 #
How to read RData file with R
This worked for me:
load(url("https://github.com/tvganesh/yorkrData/raw/master/IPL/IPL-T20-matches/Chennai%20Super%20Kings-Deccan%20Chargers-2008-05-06.RData"))
I get a dataframe overs
from the RData-file.
The url is taken from the Download-button of the github-page to get the raw file.
Related Topics
Cannot Read File with "#" and Space Using Read.Table or Read.CSV in R
Car::Scatter3D in R - Labeling Axis Better
Generally Disable Dimension Dropping for Matrices
Enclosing Variables Within for Loop
Getsymbols and Using Lapply, Cl, and Merge to Extract Close Prices
Reshaping Data to Plot in R Using Ggplot2
Calculate Percentages of a Binary Variable by Another Variable in R
Topic Models: Cross Validation with Loglikelihood or Perplexity
How to Run a R Language(.R) File Using Batch File
How to See All Rows of a Data Frame in a Jupyter Notebook with an R Kernel
How to Exclude Specific Variables from a Glm in R
Are Data Tables with More Than 2^31 Rows Supported in R with the Data Table Package Yet
Contrast Between Label and Background: Determine If Color Is Light or Dark
R 3.0.3 Rbind Multiple CSV Files
How to Know Which Cluster Do the New Data Belongs to After Finishing Cluster Analysis