Fatal error: creating temporary file for '-e' failed

Hi,
When I tried to knit my R markdown file to pdf file, it suddenly showed the following error,

      Fatal error: creating temporary file for '-e' failed

I have successfully knitted my files before, and I think it didn't related to the codes, as I tried to knit the default Rmarkdown file, it still failed.
I searched online and only found out solutions for Windows, and I was using the MacOS system.
Can anyone help to solve the problem, thanks!

Hi, and welcome. A reproducible example, called a reprex would be helpful here.

Also, in RStudio, if you select File | New File | R Markdown | Document | pdf, can you knit the file? What version of R and R Studio? Are you on Mojave?

Thanks for your reply!
I cannot knit the file, and the fatal error occurred. I re-downloaded the latest version of both R and Rstudio, and the error still showed up.