-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[R-package] Use Rprintf for logging in the R package (fixes #1440, fixes #1909) #2901
Conversation
# CRAN may run RD CMD CHECK instead of R CMD CHECK, | ||
# which can lead to this infamous error: | ||
# 'R' should not be used without a path -- see par. 1.6 of the manual | ||
find_program( | ||
LIBR_EXECUTABLE | ||
NO_DEFAULT_PATH | ||
HINTS "${CMAKE_CURRENT_BINARY_DIR}" "/usr/bin" "/usr/lib/" | ||
NAMES R R.exe | ||
) | ||
|
||
if(LIBR_EXECUTABLE MATCHES ".*lightgbm\\.Rcheck.*") | ||
message(FATAL_ERROR "Hit this block. '${LIBR_EXECUTABLE}'") | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section is something I added that you won't find in the xgboost
script. It solves an issue that only matters at testing time...basically inside of R CMD check
, CRAN actually runs a different command called RD CMD check
which uses a special version of R
/ R.exe
. We faced this in pkgnet as well.
From Writing R Extensions
Do not invoke R by plain R, Rscript or (on Windows) Rterm in your examples, tests, vignettes, makefiles or other scripts. As pointed out in several places earlier in this manual, use something like
"$(R_HOME)/bin/Rscript"
"$(R_HOME)/bin$(R_ARCH_BIN)/Rterm"
with appropriate quotes (as, although not recommended, R_HOME can contain spaces).
The hints that I gave here will only work on Unix-alike operating systems. When I do #2335 it will get changed. But since this only matters for testing (in the context of R CMD check
), not for normal use, I think it's ok to merge.
Without this block, the builds will fail with this error:
'R' should not be used without a path -- see par. 1.6 of the manual
@@ -39,9 +39,9 @@ | |||
|
|||
// 64bit pointer | |||
#if INTPTR_MAX == INT64_MAX | |||
typedef int64_t R_xlen_t; | |||
typedef int64_t xlen_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to rename this type to avoid conflicts with R_xlen_t
defined in R's headers.
#include <R_ext/Error.h> | ||
#include <R_ext/Print.h> | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for those who are new to it:
R_NO_REMAP
: Do not change symbols likeRf_error()
toerror()
R_USE_C99_IN_CXX
: Make sure thatRvprintf()
is defined. (reference)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: R_USE_C99_IN_CXX
is defined in R_ext/Print.h
in R 4.0. Will this break when using R 4.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jameslamb Awesome job!
Below are some initial comments.
I just tried building this branch on my Windows laptop (Windows 10, R3.6.1, Visual Studio 16 2019) with The first time I ran I did hit https://github.com/jameslamb/LightGBM/blob/feat/r-header/R-package/src/cmake/modules/FindLibR.cmake#L41, but that was easy to fix by following the error message and adding the Rtools minGW |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jameslamb I left some comments. Please take a look.
7568546
to
73eafe5
Compare
I just rebased to |
|
||
// R code should write back to R's error stream, | ||
// otherwise to stderr | ||
#ifndef LGB_R_BUILD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should agree on preprocessor directive indentations on a later PR. ping @guolinke @StrikerRUS @jameslamb for later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See R-devel (R 4.0): https://cran.r-project.org/doc/manuals/r-devel/NEWS.html in C-level facilities:
Header ‘R_ext/Print.h’ defines R_USE_C99_IN_CXX and hence exposes Rvprintf and REvprintf if used with a C++11 (or later) compiler.
Do we need a workaround for it?
#include <R_ext/Error.h> | ||
#include <R_ext/Print.h> | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: R_USE_C99_IN_CXX
is defined in R_ext/Print.h
in R 4.0. Will this break when using R 4.0?
Still investigating, but for the sake of documenting the discussion... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems there is no issue for R_USE_C99_IN_CXX
according to R_ext/Print.h
in R-devel (4.0):
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 1998-2019 The R Core Team
*
* This header file is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This file is part of R. R is distributed under the terms of the
* GNU General Public License, either Version 2, June 1991 or Version 3,
* June 2007. See doc/COPYRIGHTS for details of the copyright status of R.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, a copy is available at
* https://www.R-project.org/Licenses/
*/
/* Included by R.h: API */
#ifndef R_EXT_PRINT_H_
#define R_EXT_PRINT_H_
#ifdef __cplusplus
/* If the vprintf interface is defined at all in C++ it may only be
defined in namespace std. It is part of the C++11 standard. */
# if __cplusplus >= 201103L && !defined(R_USE_C99_IN_CXX)
# define R_USE_C99_IN_CXX
# endif
# ifdef R_USE_C99_IN_CXX
# include <cstdarg>
# define R_VA_LIST std::va_list
# endif
extern "C" {
#else
# include <stdarg.h>
# define R_VA_LIST va_list
#endif
Thanks for the review @Laurae2 ! I won't merge until @StrikerRUS and I agree on some of the lingering comments on |
@StrikerRUS I saw you resolved the comment threads on Thanks for the review! btw I made PR into |
@jameslamb Please give me some time to make a second round of review. |
sure no hurry at all! Glad that I asked |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jameslamb Finally got a minute to drop a second round of review. Sorry for the delay!
no problem! I'll look at these right now. |
Co-Authored-By: Nikita Titov <[email protected]>
Yeah, it seems to be so... I cannot remember how many times I re-run Travis macOS builds last days. Also, Travis had some problems with macOS recently: https://www.traviscistatus.com/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jameslamb Overall looks good! But please take a look at some my questions below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jameslamb LGTM! Great step towards CRAN release! 🎉
Thanks a lot for your patience!
…#1440, fixes microsoft#1909) (microsoft#2901) * [R-package] started cutting over from custom R-to-C interface to R.h * replaced LGBM_SE with SEXP * fixed error about ocnflicting definitions of length * got linking working * more stuff * eliminated R CMD CHECK note about printing * switched from hard-coded include dir to the one from FindLibR.cmake * cleaned up formatting in FindLibR.cmake * commented-out everything in CI that does not touch R * more changes * trying to get better logs * tried ignoring * added error message to confirm a suspicion * still trying to find R during R CMD CHECK * restore full CI * fixed comment * Update R-package/src/cmake/modules/FindLibR.cmake * changed strategy for finding LIBR_HOME on Windows * Removed 32-bit Windows stuff in FindLibR.cmake * Update R-package/src/cmake/modules/FindLibR.cmake * Update CMakeLists.txt Co-Authored-By: Nikita Titov <[email protected]> * Update CMakeLists.txt Co-Authored-By: Nikita Titov <[email protected]> * Update R-package/src/cmake/modules/FindLibR.cmake Co-Authored-By: Nikita Titov <[email protected]> * removed some duplication in cmake scripts * Update R-package/src/cmake/modules/FindLibR.cmake Co-Authored-By: Nikita Titov <[email protected]> * Update R-package/src/cmake/modules/FindLibR.cmake Co-Authored-By: Nikita Titov <[email protected]> * Update R-package/src/cmake/modules/FindLibR.cmake Co-Authored-By: Nikita Titov <[email protected]> * Update R-package/src/cmake/modules/FindLibR.cmake Co-Authored-By: Nikita Titov <[email protected]> * Update R-package/src/cmake/modules/FindLibR.cmake Co-Authored-By: Nikita Titov <[email protected]> * Update R-package/src/cmake/modules/FindLibR.cmake Co-Authored-By: Nikita Titov <[email protected]> * added LIBR_CORE_LIBRARY back * small fixes to CMakeLists * simplified FindLibR.cmake * some fixes for windows * Apply suggestions from code review Co-Authored-By: Nikita Titov <[email protected]> * allowed for directly passing LIBR_EXECUTABLE to FindLibR.cmake * reorganized FindLibR.cmake to catch more cases * clean up inconsistencies in R calls in FindLibR.cmake * Update R-package/src/cmake/modules/FindLibR.cmake Co-Authored-By: Nikita Titov <[email protected]> * removed unnecessary log messages * removed unnecessary unset() call Co-authored-by: Nikita Titov <[email protected]>
This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
This PR proposes a change to get the R package closer to CRAN's standards (#629). See #1440 and #1909 for background. The basic issue, as documented in Writing R Extensions, is this:
To get LightGBM into compliance with this check, I propose using
Rprintf()
andRvprintf()
from R's headers. This is the approach CRAN recommendsNotes for Reviewers
cmake/modules/FindLibR.cmake
was included to find R and its headers on any system. It borrows heavily fromxgboost
's implementation.mpi
) is failing but I think it is unrelated.R CMD check lightgbm_2.3.2.tar.gz --as-cran
and can confirm that this NOTE is gone!