Getting data file name from loading .rda file in R

I am trying to upload a .rda file to r, which was a saved data framework. I do not remember his name.

I tried

a<-load("al.rda") 

which then does not allow me to do anything with a. I get an error

 Error:object 'a' not found 

I also tried using the = sign.

How to download this .rda file so that I can use it?

I restarted R with the download ("al.rda"), and I know I got the following error:

 Error: C stack usage is too close to the limit 
+6
source share
5 answers

I had to reinstall R ... somehow it was corrupt. The simple command I expected from

 load("al.rda") 

finally worked.

+4
source

Use 'attach' and then 'ls' with the name argument. Sort of:

 attach("al.rda") ls("file:al.rda") 

The data file is now on your search path at position 2, most likely. At:

 search() ls(pos=2) 

for enlightenment. Entering the name of any object stored in al.rda will now receive it if you do not have something in the search position 1, but R will probably warn you with a message about a thing masking another thing, if any.

However, now I suspect that you have not saved anything in your RData file. Two reasons:

  • You say you did not receive an error message
  • load says nothing loaded

I can duplicate this situation. If you save the file (file = "foo.RData"), you get an empty RData file - what you probably wanted to do was save.image (file = "foo.RData"), which saves all your objects.

How big is your .rda file? If its less than 100 bytes (my empty RData files are 42 bytes long), then I suspect what happened.

+5
source

The load function returns a list of variables that it loaded. I suspect that you are really getting an error message while loading "al.rda". What exactly does R display when loading?

An example of how it should work:

 d <- data.frame(a=11:13, b=letters[1:3]) save(d, file='foo.rda') a <- load('foo.rda') a # prints "d" 

To make sure that the load function you are really calling is the original:

 find("load") # should print "package:base" 

EDIT . Since you now receive an error message while downloading a file, it is probably corrupted in some way. Try this and say it prints:

 file.info("a1.rda") # Prints the file size etc... readBin("a1.rda", "raw", 50) # reads first 50 bytes from the file 

Without access to the file, it is difficult for you to explore more ... Perhaps you could somehow share the file (http://www.filedropper.com or similar)?

+4
source

I had a similar problem and it was solved without reinstalling R. For example, by doing

load("al.rda) works fine, however if you do this a <- load("al.rda") will not work.

+1
source

I usually use save to save only one object, and then I use the following utility method to extract this object into the given variable name using load, but into a temporary namespace to avoid overwriting existing objects. Perhaps this will be useful for others:

 load_first_object <- function(fname){ e <- new.env(parent = parent.frame()) load(fname, e) return(e[[ls(e)[1]]]) } 

Of course, this method can be extended to also return named objects and lists of objects, but this simple version is most useful to me.

0
source

Source: https://habr.com/ru/post/903995/


All Articles