Hello,

1. Try path.expand().

flname <- path.expand("~/Baseball/RetroSheetDocumentation/ari18.test2.rda")

2. To load in the global environment

load(flname, envir = .GlobalEnv)

3. But read the docs. From ?load:

load(<file>) replaces all existing objects with the same names in the current environment (typically your workspace, .GlobalEnv) and hence potentially overwrites important data. It is considerably safer to use envir = to load into a different environment, or to attach(file) which load()s into a new entry in the search path.


So Duncan's suggestion to create a new environment and load the data there might be sound advice. Check if your data set exists in the .GlobalEnv first, then load() it.

ls(pattern = "^ari", envir = .GlobalEnv)


Hope this helps,

Rui Barradas

Às 18:06 de 26/09/19, Duncan Murdoch escreveu:
On 26/09/2019 12:55 p.m., Phillip Heinrich wrote:
Just when I think I’m starting to get the hang of R I run into something that sends me back to Go without collecting $200.

The working directory seems to be correct when I load an .rda file but it is not there and it is not in the Global Environment in the upper right hand window in RStudio.
getwd()
[1] "C:/Users/Owner/Documents/Baseball/RetroSheetDocumentation"
load("~/Baseball/RetroSheetDocumentation/ari18.test2.rda")
ari18.test2
Error: object 'ari18.test2' not found
ls()
  [1] "ari18.test3"       "array1"            "array2" "BaseballArticles"  "BaseballArticles2"   [6] "BaseballArticles3" "BBCorpus"          "BBtdm" "firstfunction"     "folder" [11] "h"                 "matrix"            "matrix2" "matrix3"           "n" [16] "seq"               "testvector"        "u" "vec"               "x"
[21] "y"                 "yourname"
             >


Somehow ari18.test3 loaded but ari18.test2 will not.

What am I missing here?

The filename (~/Baseball/RetroSheetDocumentation/ari18.test2.rda) has no connection to the variables that would be created when you load it. Finding out what's in that file isn't obvious:  you need to load it into an empty location (either your global environment in a clean new session, or one created specially for the purpose).  E.g.

  env <- new.env()
  load("~/Baseball/RetroSheetDocumentation/ari18.test2.rda", envir = env)
  ls(envir = env)

This will load the object(s) from that file into the environment env. You could copy them from there to somewhere else, use them from there, or just load again into the global environment, now you know what you're getting.

Duncan Murdoch

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to