From @oko| @end|ng |rom |n@@-tou|ou@e@|r  Fri Sep 13 18:06:15 2019
From: @oko| @end|ng |rom |n@@-tou|ou@e@|r (Serguei Sokol)
Date: Fri, 13 Sep 2019 18:06:15 +0200
Subject: [Rd] Fw: Calling a LAPACK subroutine from R
In-Reply-To: <BF20B805-1DC0-4DDB-9A46-ED19750A05E1@xs4all.nl>
References: <DM6PR04MB39154A2AC724DC1A1ED7ABFEC3B60@DM6PR04MB3915.namprd04.prod.outlook.com>
 <DM6PR04MB3915AAF7C4F24F2D854AD8FBC3B10@DM6PR04MB3915.namprd04.prod.outlook.com>
 <329F5311-5041-4297-B5C3-C05C258B1AF7@xs4all.nl>
 <026463ed-e8df-3d28-fef9-94ac3b1c740b@insa-toulouse.fr>
 <BF20B805-1DC0-4DDB-9A46-ED19750A05E1@xs4all.nl>
Message-ID: <9acd6f7c-0ebc-3785-b871-184435022151@insa-toulouse.fr>

On 12/09/2019 11:07, Berend Hasselman wrote:
>> On 12 Sep 2019, at 10:36, Serguei Sokol<sokol at insa-toulouse.fr>  wrote:
>>
>> On 11/09/2019 21:38, Berend Hasselman wrote:
>>> The Lapack library is loaded automatically by R itself when it needs it  for doing some calculation.
>>> You can force it to do that with a (dummy) solve for example.
>>> Put this at start of your script:
>>>
>>> <code>
>>> # dummy code to get LAPACK library loaded
>>> X1 <- diag(2,2)
>>> x1 <- rep(2,2)
>>> # X1;x1
>>> z <- solve(X1,x1)
>>> </code>
>> another way is to use directly dyn.load():
>>
>> lapack.path <- paste0(file.path(R.home(), ifelse(.Platform$OS.type == "windows",
>>           file.path("bin", .Platform$r_arch, "Rlapack"), file.path("lib", "libRlapack"))),
>>           .Platform$dynlib.ext)
>> dyn.load(lapack.path)
> This will not work on macOS.
> The extension for dynamic libraries is .dylib.
> So you would need
>
> lapack.path <- paste0(file.path(R.home(), ifelse(.Platform$OS.type == "windows",
>           file.path("bin", .Platform$r_arch, "Rlapack"), file.path("lib", "libRlapack"))),
>           ".dylib")
>
> See the help for .Platform and dyn.load for the details for macOS.
Indeed. I was surprised to discover that .Platform$dynlib.ext is set to 
".so" on macos,
not to ".dylib". Thank you to point me to a special note about it in 
?.Platform
Is there a R predefined variable set to ".dylib" on macos ?
Meanwhile, the code for lapack path detection will become a little bit 
more complicated:

dynlib.ext=ifelse(Sys.info()[["sysname"]] == "Darwin", ".dylib", 
.Platform$dynlib.ext)
lapack.path <- paste0(file.path(R.home(), ifelse(.Platform$OS.type == 
"windows",
 ???????? file.path("bin", .Platform$r_arch, "Rlapack"), 
file.path("lib", "libRlapack"))),
 ???????? dynlib.ext)
dyn.load(lapack.path)
is.loaded("dgemv") # must be TRUE

Serguei.



[Rd] Fw: Calling a LAPACK subroutine from R
Serguei Sokol