Rstudio freezes at the start because it can't load a notebook - r

I didn't save the notebook but as in rstudio these files are still there with names like Untitled.Rmd and Untitled.nb.html. I understand the problem is that the file has a lot in it (tons of intermediate values in parameter optimization) and I noticed before the studio has problem loading when there is a lot of stuff in notebook. When I had this problem with saved notebook, I simply deleted them and the problem was solved. Now the problem is I don't know where the Untitled.Rmd and Untitled.nb.html are saved.

I found the location where these files are saved. It's in the following folder:
~/.local/share/rstudio/sources
There is bunch of folders starting with s- . The unsaved .Rmd file which was giving me problem was saved in folder named s-6ABEC66A.

Related

R studio will not remember my file path for a code chunk

When I run the following code I get an error.
library(tidyverse)
day <- read.csv("day.csv")[, -1]
glimpse(day)
Result:
Show in New Window
Error in file(file, "rt") : cannot open the connection
However when I specify the file path it works:
library(tidyverse)
setwd("~/UofUProjects/IS6489")
day <- read.csv("day.csv")[, -1]
glimpse(day)
I don't want to have to specify the file path for every single code chunk I run. Is this a setting I may have accidentally disabled? I tried deleting an re adding the file. I also tried clicking more and choosing set working directory and I still get the same error. I also tried updating Rstudio and R to the newest versions.
here is my working directory
The R markdown file I was using was saved in my download folder instead of my project folder. I was trying to specify the working directory folder with the R studio settings, and thought it would recognize however it did not work unless I actually saved the R markdown file in the project folder or used setwd(). I ran the code without the setwd() after I saved in the correct location and it worked just the way I wanted it to.

Unable to change directory in R Studio - problem with oneDrive

I am facing a problem while trying to change directory to read a csv in Rstudio.
When I type getwd() I get this as my directory:
C:/Users/giorg/OneDrive/Υπολογιστής/MSc_Data_Science_&_CI/Introduction to Statistical methods for Data Science/Coursework
So when I try to read my csv I get that error:
C:/Users/giorg/OneDrive/ÕðïëïãéóôÞò/MSc_Data_Science_&_CI/Introduction to Statistical methods for Data Science/Coursework/x.csv': No such file or directory
I tried to change through Global options > General but I still have oneDrive in my path
And when I try with setwd() I get :
setwd("C:/Users/giorg/OneDrive/Υπολογιστής/Giorgos")
Error in setwd("C:/Users/giorg/OneDrive/<U+03A5>p<U+03BF><U+03BB><U+03BF><U+03B3><U+03B9>st<U+03AE><U+03C2>/Giorgos")
cannot change working directory
Any suggestions about what should I do?
I had the same problem at some point. When I tried to change the directory I got the same error. In my case, the problem started when I changed the language of my computer. The file which I wanted to use as directory named in Greek language and after I turned my computer to English, R couldn't recognize it.
The problem solved when I renamed the file with English characters.

How to specify where cronR saves output file

I have successfully run a simple cronR tutorial using the cronR add in within R Studio. Here is the following code that I have saved in a R script file:
library(glue)
current_time <- Sys.time()
print(current_time)
msg <- glue::glue("This is a test I am running at {current_time}.")
cat(msg, file = "test.txt")
The R script file is saved within a specific project directory. The log file when the job runs is also saved there. However, the output of the script file, test.txt, is saved in my home directory. I am on a Mac. In the tutorial, it was stated that this would happen, that cron would save any output in the home directory and that if I want to change the location that I have to "specify otherwise". However, the tutorial gives no instructions for how to do this and I am not sure if I am supposed to do this through the terminal in mac and if so how? Changing the file path in the script file (e.g. Documents/test.txt) changes nothing, as the test.txt file is still saved in the home drive. I suspect I have to make this change somewhere else but I am not sure where. Any help would be appreciated.
For anyone who runs into the same issue, I was able to solve my problem by using launchD. I followed this tutorial https://babichmorrowc.github.io/post/launchd-jobs/. It worked as anticipated and now my .txt file is saved to the correct place. There is also a tutorial there for cron jobs, though if you are on a mac, launchD is apparently the preferred method.

RStudio opens up with full environmet

when I try to open RStudio, it opens with this environment and I can't open any files because it looks like RStudio is loading this large matrices.
I just want to open RStudio and start with a clean environment and no .rmd files on it
I have aleady deleted all .RData Files and .Rhistory files, uninstalled and installed both R and RStuido, and still, it opens up with all .rmd files and this large matrices on the environment
Ah, yeah, sop go to tools > global options > R General
There you'll see options to restore data on startup. Uncheck those.
If the matrices are so large that it's causing you to run out of RAM, you may need to delete the rproject file (and associated things like .rproj.user. .rhistory, .Rdata, .ruserdata --you may need to enable show hidden files to do that). Or just make a new project and start fresh (copy over the files and data from the broken project directory).

R workspaces i.e. .R files

How do I start a new .R file default in a new session for new objects in that session?
Workspaces are .RData files, not .R files. .R files are source files, i.e. text files containing code.
It's a bit tricky. If you saved the workspace, then R saves two files in the current working directory : an .RData file with the objects and a .RHistory file with the history of commands. In earlier versions of R, this was saved in the R directory itself. With my version 2.11.1, it uses the desktop.
If you start up your R and it says : "[Previously saved workspace restored]", then it loaded the file ".RData" and ".RHistory" from the default working directory. You find that one by the command
getwd()
If it's not a desktop or so, then you can use
dir()
to see what's inside. For me that doesn't work, as I only have the file "desktop.ini" there (thank you, bloody Windoze).
Now there are 2 options : you manually rename the workspace, or use the command:
save.image(file="filename.RData")
to save the workspaces before you exit. Alternatively, you can set those options in the file Rprofile.site. This is a text file containing the code R has to run at startup. The file resides in the subdirectory /etc of your R directory. You can add to the bottom of the file something like :
fn <- paste("Wspace",Sys.Date(),sep="")
nfiles <- length(grep(paste(fn,".*.RData",sep=""),dir()))
fn <- paste(fn,"_",nfiles+1,".RData",sep="")
options(save.image.defaults=list(file=fn))
Beware: this doesn't do a thing if you save the workspace by clicking "yes" on the message box. You have to use the command
save.image()
right before you close your R-session. If you click "yes", it will still save the workspace as ".RData", so you'll have to rename it again.
I believe that you can save your current workspace using save.image(), which will default to the name ".RData". You can load a workspace simply using load().
If you're loading a pre-existing workspace and you don't want that to happen, rename or delete the .RData file in the current working directory.
If you want to have different projects with different workspaces, the easiest thing to do is create multiple directories.
There is no connection between sessions, objects and controlling files .R. In short: no need to.
You may enjoy walking through the worked example at the end of the Introduction to R - A Sample Session.
Fire up R in your preferred environment and execute the commands one-by-one.

Resources