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.test2Error: 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? Thanks. [[alternative HTML version deleted]]
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
Sent from my iPhone> On Sep 27, 2019, at 12:55 AM, Phillip Heinrich <herd_dog at cox.net> 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")-/Baseball is NOT the same as your wd. Try putting in the ?Documents? ? David>> 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? > > Thanks. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.
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 at 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.
> On 26 Sep 2019, at 18:55 , Phillip Heinrich <herd_dog at cox.net> 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?(1) getwd() is irrelevant if you load() a fully qualified filename (2) if the file is actually in the working dir, load("ari18.test2.rda") should do (3) there is no guarantee that an rda file contains an object of a name related to the file name (4) To see what is inside a .rda, try e <- new.env(); load("my.rda", e); ls(e) -pd> > Thanks. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com