I use Rstudio and try to add new packages through command console.
It fails to install it for this reason
install.packages(\"devtools\"); devtools::i
As i have found out that disabling the Ransomware protection on Window Defender allows me to write in the directory.
This solved the problem. Hope it works for you.