& was unexpected at this time when initializing R

Hello!

Everytime I initialize R there is a message (in Spanish) that says something as "& was unexpected at this time when initializing R" (No se esperaba & en este momento). I get this message when installing packages too.

Thanks in advance!

are you auto-reloading former workspace on start ? advice dont.

do you have modifications to one of the many R startup configuration files (.Renviron and .Rprofile are the key ones) ? review them (or totally remove your R install and start over). startup: Friendly R Startup Configuration.

Thank you for your answer!

I've tried to remove R and re-install. Now, it doesn't appear the message when I start R:
"""
R version 4.3.2 (2023-10-31 ucrt) -- "Eye Holes"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
...
[Workspace loaded from ~/.RData]
"""
However, when I try to install for example the GenomeInfoDbData package. It appears again the & message:
"""

BiocManager::install("GenomeInfoDbData")
'getOption("repos")' replaces Bioconductor standard repositories, see 'help("repositories", package = "BiocManager")' for
details.
Replacement repositories:
CRAN: https://cran.rstudio.com/
Bioconductor version 3.18 (BiocManager 1.30.22), R 4.3.2 (2023-10-31 ucrt)
Installing package(s) 'GenomeInfoDbData'
installing the source package ‘GenomeInfoDbData’

probando la URL 'https://bioconductor.org/packages/3.18/data/annotation/src/contrib/GenomeInfoDbData_1.2.11.tar.gz'
Content type 'application/x-gzip' length 12284235 bytes (11.7 MB)
downloaded 11.7 MB

No se esperaba & en este momento.

The downloaded source packages are in
‘C:\Users\albaf\AppData\Local\Temp\RtmpGsHdUZ\downloaded_packages’
Installation paths not writeable, unable to update packages
path: C:/Program Files/R/R-4.3.2/library
packages:
cluster, foreign, lattice, Matrix, nlme, rpart
Warning message:
In install.packages(...) :
installation of package ‘GenomeInfoDbData’ had non-zero exit status
"""

About the modifications in the .Renviron and .Rprofile files, I didn't manage to find them. If you could, explain how to check them, please.

Thanks again!

This relates to my first advice to you;
I recommend against this; any mistake you make, you wlll carry around ....
How to delete your saved workspace in R - That Darn Data!
(choose Never as per the image)

Thank you! I changed this setting. However, it didn't help with the message "& was unexpected at this time" when installing a package.

Did you restart your session ?

Yes, I closed Rstudio and opened it again. The message doesn't appear anymore when initializing. I tried to install the package above and the same error appeard.

As a windows user you may need to run Rstudio as an administrator in order to make these installations.
reference : bioconductor - installation path not writable R, unable to update packages - Stack Overflow

I already did this. It doesn't help. This only helps to install the updates of the dependencies "cluster, foreign, lattice...". Now that I reopened Rstudio as an administrator the error slightly changes, but the "No se esperaba & en este momento" (& was unexpected at this time) still appears.

"""
BiocManager::install("GenomeInfoDbData")
'getOption("repos")' replaces Bioconductor standard repositories, see 'help("repositories", package = "BiocManager")' for
details.
Replacement repositories:
CRAN: https://cran.rstudio.com/
Bioconductor version 3.18 (BiocManager 1.30.22), R 4.3.2 (2023-10-31 ucrt)
Installing package(s) 'GenomeInfoDbData'
installing the source package ‘GenomeInfoDbData’

probando la URL 'https://bioconductor.org/packages/3.18/data/annotation/src/contrib/GenomeInfoDbData_1.2.11.tar.gz'
Content type 'application/x-gzip' length 12284235 bytes (11.7 MB)
downloaded 11.7 MB

No se esperaba & en este momento.

The downloaded source packages are in
‘C:\Users\albaf\AppData\Local\Temp\RtmpK8JCKI\downloaded_packages’
Warning message:
In install.packages(...) :
installation of package ‘GenomeInfoDbData’ had non-zero exit status
"""

Could this be something related to the .Renviron file you suggested earlier? If you could explain how to check, please.

Thank you so much for the patience and help!

i use the R package usethis which has edit_r_environ() helper function

Is it possible that I don't have these files? I've looked everywhere and can't seem to find them.

yes, they arent mandatory, if usethis::edit_r_environ() opens an empty file for you then you didnt have it.

I've googled your message and seen mention from the python community about terminal issues concerning vs code and miniconda. Not sure how it could be relevant for you ; seems a very unusual issue. Sorry I cant help further.

Not sure about the answer either, I might have a few more ideas.

First, my impression is that when you ran it as administrator, {GenomeInfoDbData} was properly installed. You did get a warning, but no error. Can you now run this?

library(GenomeInfoDbData)

Second, does this only happen in RStudio, or also if you start RGui? If only RStudio, you can try changing the default terminal in Tools > Global Options > Terminal (since it may be a Powershell problem).

Do you get any such warning when using the terminal inside RStudio? Next to the console:
image

In particular, click on the "Terminal 1" and select "New Terminal", to see if it's something about the shell profile.


A couple more ideas related to installation, I don't think that's the problem, since you have this warning message at initialization.

Does this also appear when you try installing packages from CRAN? For example, does this work?

install.packages("dplyr")

You could also make sure you install the latest version of RTools, in case it's something to do with compiling packages.

Hello!

While I was trying to look for an answer online, I realised the same message appeared when initializing the Command Prompt. I found this website Windows cmd.exe & was unexpected at this time | Scientific Computing and solved it with Registry Editor.

However, my problem with the installation in R wasn't solved. Eventhough the message didn't appear, the rest of the error message was the same. Also, when I run the Command Prompt, an error appears that says something like "Process ended with code 1 (0x00000001)". I think this is a major problem related to Windows in my account. For anyone that might encounter this same problem, I read somewhere (don't remember the exact page since I've been looking everywhere lol) that the solution was to restore a previous version of Windows that worked fine or to create another account on your laptop. I tried the latter and everything goes fine.

Thank you so much for your help anyway!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.