0

(This is not a duplicate of Reading Rds file from git)

Is there a way of reading an .rds file in R (or any other file) from a specific git commit without having to checkout the commit nor create a temporary file (not from GitHub, but for example from a bare or non-bare repo saved locally or on a server)?

I tried the following, but not surprisingly it does not work (assuming you have a git repo with some commits and a file a.rds):

b <- readRDS(system("git show 9358:a.rds"))
> Error in readRDS(system("git show 9358:a.rds")) : 
    invalid 'description' argument
Stefano
  • 1,405
  • 11
  • 21

1 Answers1

0

Had the same problem with a text file a few days ago. I solved by saving the file (in the system call) before reading it. I guess in your case it would be something in the lines of:

# Target file output
output_dest <- "~/path/to/output.rds"

# Output stdout to file (in this case 3 commits before HEAD)
system(sprintf('show HEAD~3:your_repo/file.rds > %s', output_dest))

readRDS(output_dest)
anddt
  • 1,589
  • 1
  • 9
  • 26
  • The questions asks how to achieve that without having to save the output to a file, but rather by reading the content directly in memory in the R session, like reading from a url would do. – Stefano Apr 09 '20 at 15:56