@@ -126,30 +126,45 @@ openmp_directives <- function(parallel, private = NULL) {
126126 )
127127}
128128
129- openmp_config_value <- function (name ) {
130- r_cmd <- R.home(" bin/R" )
131- if (identical(.Platform $ OS.type , " windows" ) && ! file.exists(r_cmd )) {
132- r_cmd <- paste0(r_cmd , " .exe" )
133- }
134- out <- tryCatch(
135- suppressWarnings(system2(
136- r_cmd ,
137- c(" CMD" , " config" , name ),
138- stdout = TRUE ,
139- stderr = TRUE
140- )),
141- error = function (e ) character ()
142- )
143- status <- attr(out , " status" )
144- if (! is.null(status )) {
145- return (" " )
146- }
147- value <- trimws(paste(out , collapse = " " ))
148- if (! nzchar(value ) || grepl(" ^ERROR:" , value )) {
149- return (" " )
129+ openmp_config_value <- local({
130+ cached <- NULL
131+
132+ function (name ) {
133+ if (is.null(cached )) {
134+ cached <<- list ()
135+ }
136+ cached_value <- cached [[name ]]
137+ if (! is.null(cached_value )) {
138+ return (cached_value )
139+ }
140+
141+ r_cmd <- R.home(" bin/R" )
142+ if (identical(.Platform $ OS.type , " windows" ) && ! file.exists(r_cmd )) {
143+ r_cmd <- paste0(r_cmd , " .exe" )
144+ }
145+ out <- tryCatch(
146+ suppressWarnings(system2(
147+ r_cmd ,
148+ c(" CMD" , " config" , name ),
149+ stdout = TRUE ,
150+ stderr = TRUE
151+ )),
152+ error = function (e ) character ()
153+ )
154+ status <- attr(out , " status" )
155+ if (! is.null(status )) {
156+ cached [[name ]] <<- " "
157+ return (" " )
158+ }
159+ value <- trimws(paste(out , collapse = " " ))
160+ if (! nzchar(value ) || grepl(" ^ERROR:" , value )) {
161+ cached [[name ]] <<- " "
162+ return (" " )
163+ }
164+ cached [[name ]] <<- value
165+ value
150166 }
151- value
152- }
167+ })
153168
154169openmp_fflags <- function () {
155170 env_flags <- trimws(Sys.getenv(" QUICKR_OPENMP_FFLAGS" , " " ))
0 commit comments