Unexpected token in R with chunks - r

i started a new R Project and everytime I use chunks (regardless from the topic within) the task went trough but i receive an "unexpected token '`" and a red dot in the referring line (see picture)chunks unexpected token R.
Also, when my script crushes and/or is reopened all my chunks are gone until I renamed the script.
What am I doing wrong?
Thanks in advance for your help
(R version is 4.1.2. "Bird Hippie")

I found the solution,
due to a complete R update I had to install the "rmarkdown" (again).
Afterwards (and a run through the code) everything worked out well.
Maybe this issue might be interesting for others too, so I will keep it here :) .

Related

RStudio tells me packages required in a .r file are not installed - but I've been using them for years! What gives?

I've been using RStudio for a long while now (not that I'm any good at it). Over the course of the years I've installed many packages for use in my work, from the mega-popular (e.g. tidyverse) to the very niche.
I wake up this morning and get into RStudio, where the three .r files I've been working on for different projects are open. At the top of each of them, it tells me with a little yellow warning triangle that packages _____ are "required but not installed". It says that for every package I've specified in each .r file with library().
I'm not sure what to do to fix this. When I search my hard drive for the names of packages, they still show up: sure enough, tidyverse still occupies the directory "~\R\win-library\3.5\tidyverse", for example. I've attempted restarting the R session a number of times, too, with no luck. I feel like this is some very obvious oversight on my part but I can't see what it is. I've also done a few searches of StackOverflow to see if anyone's had this happen before - I can't be the first - but I haven't found anything. If I've missed it, I apologize. Also, I'm running
What is RStudio not "seeing" here that it saw before?
tl;dr - RStudio is telling me that I don't have packages I've used for years, as recently as yesterday. What's happening here?

Why does R crash when adding DESeq2 as dependency to R package?

I'm writing an R package using devtools and roxygen2. Note that this is my first time making a package, so maybe I am missing something important.
I want to add a dependency, the package, DESeq2. I have tried to do this in a number of ways, but believe the right way is to add the following to my DESCRIPTIONS file.
Depends:
DESeq2
If I add this, when I build and reload I get a fatal error. When running in RStudio it just gives a "Fatal Error" dialog and restarts the application. It appears to build, but when it does, library(myPackage), it crashes immediately.
If I remove the Depends section from the DESCRIPTIONS file it builds and loads fine. What's more, if I include a different package, for example, ggplot2, then it builds and loads fine as well.
What about a package would cause it to fail to load as a dependency and completely crash? Is there another way to require it or is there any way to dig deeper into the cause?
Thanks very much in advance.

Error: Unable to establish connection with R session

I am having trouble pulling down data sets from the web (https://api.fda.gov) FDA API. The connection is fine and it appears generate more than 4000 JSON records. The problem is, when it is done, R gives me the below error and I am no longer able to do anything in RStudio - I basically have to force quit. I've seen references to similar issues, but haven't been able to find a solution.
Error: Unable to establish connection with R session
I assume that you are using RStudio? There is a problem with RStudio and pulling large data sets. See here: Wang's Tech Blog and here: RStudio Support.
I suggest just using R in the terminal when you run scripts that pull large data-sets.
I was able to solve all problems by deactivating/deinstalling the antivirus software (Avast)
I also ran into this error. Uninstalling avast did not work for me. I uninstalled r and r studio and reinstalled r and r studio and this solved my problem.

tools:RGUI disappears from globalenv R

I just installed the newest version of R for my OS -- R version 3.1.3 for MAC. The tools:RGUI does not load properly. Half the time, I open R and search() does not include tools:RGUI. The other half of the time, it does appear but then quickly disappears from the global environment. As a result, I cannot use the help function or search for and install packages. My internet connection is fine. Any ideas?
I think I figured out the problem; I had detach() at the start of my code. I do not normally attach data as I have been told it is a bad habit that can lead to problems. They were right. I have deleted all the references to attach and detach and things seem to work fine now.

Refresh R console without quitting the session?

I usually open the R console all day long, but sometimes I need to clean my history and my workspace's background so that I can test functions or load new data.
I'm wondering whether there is an easier way to use a command line in .Rprofile so that I can refresh the R console without quitting or rebooting my current session.
What I have usually done for this is to q() without saving and then start R again and clean the History. I think somebody here might be able to give me some better suggestions.
Thanks in advance.
For what concerns history, in UNIX-like systems (mine is Debian) this command refreshes it
loadhistory("")
However, as said in comments, loadhistory seems to be platform-dependent.
Check your ?loadhistory if present on your platform. Mine says:
There are several history mechanisms available for the different
R consoles, which work in similar but not identical ways. There
are separate versions of this help file for Unix and Windows.
The functions described here work on Unix-alikes under the
readline command-line interface but may not otherwise (for
example, in batch use or in an embedded application)

Resources