Rstudio crashes while saving R-script

Hello!

Hope you're well.
I have installed r and r studio. It can work if I only run an R-script. However, when I attempt to save my file, R studio crashes. I click the blue floppy disk or select file and save as. My file manager pops up to allow me to select where I want to save. But then it freezes and disappears.

Does anyone have any thoughts on what I'm doing wrong? I know that someone met the same problem several years ago. But my computer is Lenovo, not Dell.

In addition, R-Studio seems to run some code automatically and display some error message when I start R-Studio. It seems to have run 'gsub("\n", "", code): input string 1 is invalid' and translated some parts of my existing code. That make me confused. I don't know whether it is related to the crashing.

Other potentially useful messages:
Rstudio version: RStudio-2024.09.0-375
R version: R 4.4.0
OS: Windows 10.19045.5011
Machine:Lenovo Legion Y7000
The last time I used normally: 2024 May 28

Thanks!

Try resetting RStudio's state and see if it eliminates the freeze/crash or at least gets rid of the messages regarding gsub.

Well,I renamed that directory but I found it doesn't work. When I open an existing R-script file, it still show message about 'gsub'. And it still crashes when I attempt to save a new script. Though I can successfully save an existing file after editing it .

If you go to Tools > Global Options ... > Code > Saving, are either of the first two boxes under General checked, and what are the settings for "Line ending conversion" and "Default encoding"? The message about gsub looks like something is trying to remove line feeds from an argument named "code" (the content of the file being saved?) and not doing it correctly.

Here're the settings.

Neither the first two boxes are checked.

You said "My file manager pops up to allow me to select where I want to save. But then it freezes and disappears." Just to be clear, you're saying that RStudio freezes and disappears (not the file manager)? If you create a new R script, type something innocuous in (say x <- 1) and save it, the crash occurs?

It is the RStudio that freezes and disappear not the file manager. It occurs after I click the 'Save' buttom on the file manager.
I just found something special. If I save the file named with numbers (example: 1.R), it is saved successfully. If I name the file with any English character, the crash occurs.

That last bit is curious. By any chance is your computer set up with something other than English as the default language?

The default language of my computer is Chinese because I'm from China. I have run RStdio in that environment for 5 years. Is it because I reinstalled the OS in May this year?

Good question. Unfortunately I'm monolingual (English) and a Linux user, so I have no idea. Can you switch the default language to English (without screwing things up too badly) as an experiment and see if that lets RStudio save files (then switch it back)? If yes, at least we have narrowed down the problem.