I have no idea what's going on, I never got this problem before, but I'm working on a new project and whenever I try to call grid.arrange or any kind of plot now in a loop of plots, R displays the plots from my last project which I obviously don't want anymore which is the last time I used grid.arrange. It refuses to display all of the plots together and I have to go through all of them one by one. It doesn't make sense since my computer has turned off and logged on with new updates since the last time I was working on that project. I tried rm=ls() and I still get the same problem. Help :/
the function is rm(list=ls()). You could also try file.remove(".RData") in the working directory.
Related
I'm trying to look at some data in RStudio using View(). Code is running smoothly, but for some reason the display looks kind of off. Column labels are a little off from the rest of the column. See image here or below: https://ibb.co/gTJFCj0
Scrolling is also incredibly slow. It takes close to 5 seconds for it to respond at all.
I'm new to R, so I have absolutely no clue where to even begin looking. I'm guessing it may be that RStudio is trying to display everything at once?
I have a question about R. I think I forgot to save one of the scripts I was working on and I'm trying to get it back somehow. The script involved commands to create plots.
If I use the command:
print(nameoftheplot)
I am able to print the plot. Does this mean that R still has the script somewhere in the working memory? And how can I get it back?
Thanks for your help!
With luck, your commands are saved in R’s history; you should immediately perform
savehistory('history.r')
This usually contains all the last commands you executed.
I am able to print the plot. Does this mean that R still has the script somewhere in the working memory?
Unfortunately, no. However, it still has the print object in memory, and you can dump that to retrieve some information:
dput(nameoftheplot)
Whether this is useful depends on how exactly the plot was created.
Apart from that, the following two things can give you information about the last state of your script:
ls()
will show you all the objects you defined in the global environment. You can look at their values for clues. In particular, if you defined functions, their code will be available in its entirety.
search()
will show you which packages your script loaded and attached.
From this you may be able to reconstruct large parts of your code.
I've been trying to get started using R in PowerBI. However, the lack of intellisense and the lack of console output is hindering me. As I can't develop the script in RStudio or in Visual Studio with those aids.
EDIT: PowerBI does a nice thing where you can import data into the application and then work with the drag and drop tools to play around with the data, then when you select data fields that you want to add to an R plot, it creates an R stub that pulls those fields into a data.frame which makes things easy. However, that data is "inside" Power BI, I can't do the same thing in R studio because that data context doesn't exist.
What options are there? Am I missing something?
Thanks.
I think that what you are looking for is R tools for VS. It should make intellisense pick up the context and tell you what you can do with each object. Then for the output, can't you print and check the results in the output window in VS?
This also has R interactive window so when you debug you have a window to place code in, and evaluate it in that context. Say you have a method and you want to debug a statement plot(x, exp(x), type="l", col="green"), instead of making a fix at a time and then re-running to check the results, you can just make the fix say plot(x, exp(x), type="l", col="red") and see how that evaluates. This comes in handy when you wanna try a couple of things and check the results, since you can do it in one go, instead of "making one change and running it" x times.
Let me know if this does the job for you.
The only data context you have in R inside Power BI are Tables, which you pass in parameters of the call of R.Execute. Behind the scene, these Tables will be just dropped on disk as csv and then R process will pick them in order to do whatever you want. Actually this is the only relation between R and PowerBI desktop, if we speak about Transformations using R.
You can easily save such a context from PowerBI using R script of just one function save.image(“filename.RData”), and then open it using load("filename.RData") in your target R development environment.
While you should always test out your R code elsewhere first, it is often not enough for debugging purposes.
for general purpose debugging, you can nest your whole script in a block like this:
out <- capture.ouput({...})
Any intermediate value can be captured in this block with a cat:
cat(intermediate_value_i_want_to_test,'\n')
After your script block is done, simply convert your output to a data.frame and each cat method call will be printed in a new row of out.
I'm new to TraMineR and sequence analysis in general. I am working on a project related to retention and recruitment of educational leaders and finding TraMineR to be very useful. This may be a simple thing (and somewhat unimportant), but I cannot seem to figure out how to name or direct the sequence tree created by GraphViz within the TraMinR package. Right now, my code is:
wardTree=as.seqtree(wardCluster,seqdata=retain.seq,diss=retain.dst,ncluster=15)
seqtreedisplay(wardTree,type="d",border=NA,showdepth=TRUE)
It produces a great graphic, but with a random file name that I cannot relocate if I accidentally close the graphic.
My main goal is to be able to uniquely name and save these graphs and pull into an R Markdown for the full project. To this point, the only thing I cannot pull in is the seqtree graphic.
Well, guess I figured it out! I didn't realize that the order in which filename command mattered...so...what seems to work out beautifully is:
wardTree=as.seqtree(wardCluster,seqdata=retain.seq,diss=retain.dst,ncluster=15)
seqtreedisplay(wardTree,type="d",border=NA,showtree=TRUE,showdepth=TRUE,filename="retaintree.png",imageformat="png")
And to incorporate the file in the Markdown i use the command
```
![](C:\Users\myname\Desktop\retaintree.png)
```{r fig.width=8.5, fig.height=11}
Hope this helps someone else along the way!
One quick question to which I could not find answer.
I want to know if it is possible to set the title of the R console to something else (using RGui, on Windows).
The main use I'm thinking of is to show some kind of progress information when running a script which takes a long time to complete.
Any suggestions?
In windows you can use the setWindowTitle function, the name that you give it will show up in the top of the window or be the label on the icon when it is minimized.
I have the following line in my .Rprofile:
utils::setWindowTitle(getwd())
So that each instance of R has a label showing which folder/directory it was opened in (I often have several open at a time that I switch between as I work on different projects). This is nice for starting R by double clicking on the .Rdata file and keeping track of which window is which.
But for indicating the progress of a long running process the progress bars are probably the better approach. In windows you can use winProgressBar or on any platform you can use txtProgessBar or tkProgressBar (the tcltk package is needed for the 2nd). The growing bar is a quick visual of the progress and you can also use the label to give a specific iteration, or other information.