How to load the actual .RData file, that is just called .RData (the compressed file that gets saved from a session) - r

Similar questions, but not the question I have, were around loading a file that someone saved as somefilename.RData. I am trying to do something different.
What I am trying to do is load the actual .RData file that gets saved from an R session. The context is that I am using 2 different computers and am trying to download the .RData file from one computer and then load this same .RData file on a different computer in RStudio.
When I download the .RData file it shows up without the “.” (e.g., it shows up as RData). When I try to rename it “.RData”, Windows will not allow me to do so.
Is there a way to do what I am trying to do?
Thanks!

After playing around with this, I was able to load the file (even though it was called “RData“ and not called “.RData”, by using RStudio by going to Session > Load Workspace... and then navigating to that file. I had used File > Open File... which did not work

Related

Why is read_excel very slow while the excel file to read from R is also opened in the Excel?

The environment is:
R: 3.6.1
readxl version: ‘1.3.1’
When I close the Excel program, read_excel takes a second or 2, but when I have the file opened in Excel, then read_excel in R can take a few minutes.
I wonder why was that?
Some programs, like Excel, put access restrictions on files while the files are open. This prevents accidental conflicts from external changes to the same file while it is open.
I don't know why specifically it would affect other tools from reading the file and why the effect would manifest as slower speed instead of complete inability. Maybe Excel is trying to monitor the access to the file and compare it to the content it has loaded.

How to reach a file without knowledge about the user directory

I'm providing a .zip with a .R file and a .xlsx file to some people
I need to make a code that can read this .xlsx file in any directory of any pc.
But as the directories vary from computer to computer, I couldn't find a solution.
IMPORTANT: I'm not using Rstudio for read this .R, so i just can use base functions
Using R - How do I search for a file/folder on all drives (hard drives as well as USB drives) This question don't solve my problem..
Take a look at the here package. When you load the library (library("here")) it sets "base" working directory and then you can use the package to construct relative file paths given that location. For example, if inside your .zip file you have an R script (e.g., My Data Analysis.R) that analyzes data that is kept within a folder called data you could read it in using, for example, read.csv(here("data", "my_csv_file.csv")) and it will construct the full appropriate file path no matter what computer it is on. Of course the file structure of the program needs to stay the same across programs.

Using R to change the extension of all files in a folder

I have a folder with a huge amount of old .xls files. I would like R to turn the whole folder (change the extension) into .csv or .xlsx files to subsequently load them into r.
I have been using R for a while, but never like this, so I do not really have an idea where to start.

What is the philosophy behind the workspaces in R?

When I start R session from some directory, R automatically loads the corresponding workspace (if it exists). After I finish to work in this workspace I can decide if I want to modify (save) the current workspace. This logic is simple and clear.
What I do not understand, is what happens if I start R from some directory and then change the working directory by setwd(). As far as I understood the workspace corresponding to the new working directory will not be "loaded". I still see the variables and history from the previous working directory. Why?
Second, when I quit() R, I replace the work-space image corresponding to the "new" working directory by the workspace corresponding to the "old" directory. Do I interpret the behavior correctly? What is the logic behind this behavior? Can I switch to another work-space from R session?
Workspaces are stored in .RData files and are automatically loaded from current working directory when you start R. But working directory itself (and setwd() function that sets it) has nothing to do with workspace. You can load any workspace by explicitly specifying any .RData file:
load("c:/project/myfile.RData")
or
setwd("c:/project/")
load()

csv files in opencpu

If I put a very small csv file in my GitHub directory so that it gets copied to /ocpu/github/username/projectname/www/ , will I be able to access the contents of the csv for use in a R function? I tried to ajax the file, but I get a 404 error even though I can see the csv file sitting in the www directory of my local server. I need to have the csv on the server as a static file rather than being uploaded by a function. Thanks
You should be able to access them like any other file. Can you post an example that shows what you are doing and what error you are getting?
That said, if you just want to use this data in your R functions, it is better to include it in the R package as an actual data file. Also see section 1.1.6 of Writing R Extensions. An example is the mapapp package, which includes a dataset called countryExData. Also see the live app.

Resources