r-lib / rcmdcheck

Run R CMD check from R and collect the results
https://rcmdcheck.r-lib.org
Other
115 stars 27 forks source link

`check()` goes wrong when my Rprofile is not empty #170

Closed mynanshan closed 3 years ago

mynanshan commented 3 years ago

I was copying and pasting the code in section 2.9 of the R package tutorial by Hadley Wickham and Jenny Bryan. When I executed the R CMD check() for the example package foofactors, an error occurred:

-- Checking ------------------------------------------------ foofactors --
Setting env vars:
* _R_CHECK_CRAN_INCOMING_REMOTE_: FALSE
* _R_CHECK_CRAN_INCOMING_       : FALSE
* _R_CHECK_FORCE_SUGGESTS_      : FALSE
* NOT_CRAN                      : true
-- R CMD check -----------------------------------------------------------
   Error in source("C:\\Users\\Lenovo\\AppData\\Local\\Temp\\RtmpoPuJln\\file78c4287d739d",  : 
     C:\Users\Lenovo\AppData\Local\Temp\RtmpoPuJln\file78c4287d739d:1:31: unexpected symbol
   1: options(vsc.use_httpgd = TRUE).Last

Then I started to debug through rcmdcheck:::make_fake_profile. I found that the process was trying to catenate my original ".Rprofile" located in "C:/User/Documents" with the definition of the function .Last. A new temporary R profile was created, in which the text is Image

As you can see from the picture, there seems to lack a line break between the old options(...) and the .Last function. After I delete the options(...) from the R profile, the check() will work successfully.

Here's some of my system info:

- Session info ---------------------------------------------------------
 setting  value                         
 version  R version 4.1.1 (2021-08-10)  
 os       Windows 10 x64                
 system   x86_64, mingw32               
 ui       RStudio                       
 language (EN)                          
 collate  Chinese (Simplified)_China.936
 ctype    Chinese (Simplified)_China.936
 tz       Asia/Taipei                   
 date     2021-10-08 
gaborcsardi commented 3 years ago

What version of rcmdcheck is this?

mynanshan commented 3 years ago

What version of rcmdcheck is this?

It is 1.3.3. I just found that there will be no problem after updating rcmdcheck to the latest version. I should have tried this. Thanks.

Btw, it is just me or it is a common problem in the old version?

gaborcsardi commented 3 years ago

AFAIR it used to happen when you did not have a terminating newline in your R profile.

FWIW it always makes sense to have a terminating newline in code files, as the lack of it is a common source of bugs. E.g. R used to have bug that it did not evaluate a last line in .Renviron without a terminating newline. I believe that this is now fixed though.