Grokbase Groups R r-help June 2016
FAQ
Hi,


I'm trying to write an R package that calls a Fortran subroutine on my Mac
os x El Capitan with Xcode 7 and gfortran 6.1, R 3.3.0. I can build and
load the library but when I try to use it in R I get this error:
library(NEpidemic)
random_epi(variable_names)

Error in .Fortran("random_epi", : "random_pi" not resolved from current
namespace (NEpidemic).


Then I tried adding useDynLib(random_epi.f95) in the NAMESPACE file,
additional to useDynLib(NEpidemic). After doing that I couldn't build the
package and it gave me another error:


Error in library.dynam(lib, package, package.lib) :
   shared object ?random_epi.so? not found
Error: loading failed
Execution halted
ERROR: loading failed


When I checked my src folder, there is only random_epi.o file. How can I
fix this issue? Any help would be much appreciated. I'm vey new to both R
and Fortran coding, especially in package building.


Thanks in advance!
Vineetha


  [[alternative HTML version deleted]]

Search Discussions

  • Eduardo M. A. M.Mendes at Jun 15, 2016 at 9:55 pm
    Hi


    Have you tried to load and run the fortran code using just a wrapper function in R? I do that as the first step in order to build a package.


    Example: fortran sources -> rk4_mod_r.f90 ,derive_henonheilles.f90, poincare_section.f90


    a) I use R CMD SHLIB rk4_mod_r.f90 ,derive_henonheilles.f90, poincare_section.f90 - o poincare_section_henonheilles_rk4.so
    b) Then I write a wrapper function in R, poinc_section_henonheilles.R
    ...
      dyn.load("poincare_section_henonheilles_rk4.so")


       out<-.Fortran("section_crossing",
                     h=as.numeric(h),
                     nphas=as.integer(nphas),..
    ...
    c) and call the function as usual.


    Please note that the function called by .Fortran is the name of the subroutine within poincare_section.f90 and not the filename.


    I take the opportunity to thank R-developers for making the calling of C and Fortran in R very easy.


    I hope this helps.


    regards


    Ed


    PS. If you need an example of a package using Fortran90, please check https://github.com/emammendes/mittagleffler <https://github.com/emammendes/mittagleffler>





    On Jun 15, 2016, at 5:20 PM, Kodalore Vijayan, Vineetha W wrote:

    Hi,

    I'm trying to write an R package that calls a Fortran subroutine on my Mac
    os x El Capitan with Xcode 7 and gfortran 6.1, R 3.3.0. I can build and
    load the library but when I try to use it in R I get this error:
    library(NEpidemic)
    random_epi(variable_names)
    Error in .Fortran("random_epi", : "random_pi" not resolved from current
    namespace (NEpidemic).

    Then I tried adding useDynLib(random_epi.f95) in the NAMESPACE file,
    additional to useDynLib(NEpidemic). After doing that I couldn't build the
    package and it gave me another error:

    Error in library.dynam(lib, package, package.lib) :
    shared object ?random_epi.so? not found
    Error: loading failed
    Execution halted
    ERROR: loading failed

    When I checked my src folder, there is only random_epi.o file. How can I
    fix this issue? Any help would be much appreciated. I'm vey new to both R
    and Fortran coding, especially in package building.

    Thanks in advance!
    Vineetha

    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.



      [[alternative HTML version deleted]]
  • Kodalore Vijayan, Vineetha W at Jun 16, 2016 at 5:03 pm
    Hi Eduardo,


      Thanks for your comments. I haven't tried the way you told me. Now when I
    tried, got the following error:


    *** caught segfault ***
    address 0x0, cause 'memory not mapped'


    Traceback:
      1: .Fortran("dataxy", n = as.integer(n), tmax = as.integer(tmax),
    alpha = as.double(alpha), beta = as.double(beta), x = as.double(0,
    length = n), y = as.double(0, length = n), tau = as.integer(0,
    length = n))
      2: out(NULL, NULL, NULL, NULL)


    Possible actions:
    1: abort (with core dump, if enabled)
    2: normal R exit
    3: exit R without saving workspace
    4: exit R saving workspace
    Selection:


    Any suggestions?


    Thanks,
    Vineetha


    On Wed, Jun 15, 2016 at 3:55 PM, Eduardo M. A. M.Mendes wrote:

    Hi

    Have you tried to load and run the fortran code using just a wrapper
    function in R? I do that as the first step in order to build a package.

    Example: fortran sources -> rk4_mod_r.f90 ,derive_henonheilles.f90,
    poincare_section.f90

    a) I use R CMD SHLIB rk4_mod_r.f90 ,derive_henonheilles.f90,
    poincare_section.f90 - o poincare_section_henonheilles_rk4.so
    b) Then I write a wrapper function in R, poinc_section_henonheilles.R
    ...
    dyn.load("poincare_section_henonheilles_rk4.so")

    out<-.Fortran("section_crossing",
    h=as.numeric(h),
    nphas=as.integer(nphas),..
    ...
    c) and call the function as usual.

    Please note that the function called by .Fortran is the name of the
    subroutine within poincare_section.f90 and not the filename.

    I take the opportunity to thank R-developers for making the calling of C
    and Fortran in R very easy.

    I hope this helps.

    regards

    Ed

    PS. If you need an example of a package using Fortran90, please check
    https://github.com/emammendes/mittagleffler



    On Jun 15, 2016, at 5:20 PM, Kodalore Vijayan, Vineetha W wrote:

    Hi,

    I'm trying to write an R package that calls a Fortran subroutine on my Mac
    os x El Capitan with Xcode 7 and gfortran 6.1, R 3.3.0. I can build and
    load the library but when I try to use it in R I get this error:

    library(NEpidemic)
    random_epi(variable_names)


    Error in .Fortran("random_epi", : "random_pi" not resolved from current
    namespace (NEpidemic).

    Then I tried adding useDynLib(random_epi.f95) in the NAMESPACE file,
    additional to useDynLib(NEpidemic). After doing that I couldn't build the
    package and it gave me another error:

    Error in library.dynam(lib, package, package.lib) :
    shared object ?random_epi.so? not found
    Error: loading failed
    Execution halted
    ERROR: loading failed

    When I checked my src folder, there is only random_epi.o file. How can I
    fix this issue? Any help would be much appreciated. I'm vey new to both R
    and Fortran coding, especially in package building.

    Thanks in advance!
    Vineetha

    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.


      [[alternative HTML version deleted]]
  • Eduardo M. A. M.Mendes at Jun 16, 2016 at 5:14 pm
    Hi Vineetha


    It seems that there are some problems in the Fortran code as far as allocating memory is concerned. If you have statements such as double preciosion :: y(n) you will need to allocate memory for the vector within the Fortran code or in the R wrapper-function. It is hard to pinpoint the error without seeing the source files.


    Cheers


    Ed





    On Jun 16, 2016, at 2:03 PM, Kodalore Vijayan, Vineetha W wrote:

    Hi Eduardo,

    Thanks for your comments. I haven't tried the way you told me. Now when I tried, got the following error:

    *** caught segfault ***
    address 0x0, cause 'memory not mapped'

    Traceback:
    1: .Fortran("dataxy", n = as.integer(n), tmax = as.integer(tmax), alpha = as.double(alpha), beta = as.double(beta), x = as.double(0, length = n), y = as.double(0, length = n), tau = as.integer(0, length = n))
    2: out(NULL, NULL, NULL, NULL)

    Possible actions:
    1: abort (with core dump, if enabled)
    2: normal R exit
    3: exit R without saving workspace
    4: exit R saving workspace
    Selection:

    Any suggestions?

    Thanks,
    Vineetha

    On Wed, Jun 15, 2016 at 3:55 PM, Eduardo M. A. M.Mendes <emammendes at gmail.com wrote:
    Hi

    Have you tried to load and run the fortran code using just a wrapper function in R? I do that as the first step in order to build a package.

    Example: fortran sources -> rk4_mod_r.f90 ,derive_henonheilles.f90, poincare_section.f90

    a) I use R CMD SHLIB rk4_mod_r.f90 ,derive_henonheilles.f90, poincare_section.f90 - o poincare_section_henonheilles_rk4.so
    b) Then I write a wrapper function in R, poinc_section_henonheilles.R
    ...
    dyn.load("poincare_section_henonheilles_rk4.so")

    out<-.Fortran("section_crossing",
    h=as.numeric(h),
    nphas=as.integer(nphas),..
    ...
    c) and call the function as usual.

    Please note that the function called by .Fortran is the name of the subroutine within poincare_section.f90 and not the filename.

    I take the opportunity to thank R-developers for making the calling of C and Fortran in R very easy.

    I hope this helps.

    regards

    Ed

    PS. If you need an example of a package using Fortran90, please check https://github.com/emammendes/mittagleffler <https://github.com/emammendes/mittagleffler>


    On Jun 15, 2016, at 5:20 PM, Kodalore Vijayan, Vineetha W <vwkv13 at mun.ca wrote:

    Hi,

    I'm trying to write an R package that calls a Fortran subroutine on my Mac
    os x El Capitan with Xcode 7 and gfortran 6.1, R 3.3.0. I can build and
    load the library but when I try to use it in R I get this error:
    library(NEpidemic)
    random_epi(variable_names)
    Error in .Fortran("random_epi", : "random_pi" not resolved from current
    namespace (NEpidemic).

    Then I tried adding useDynLib(random_epi.f95) in the NAMESPACE file,
    additional to useDynLib(NEpidemic). After doing that I couldn't build the
    package and it gave me another error:

    Error in library.dynam(lib, package, package.lib) :
    shared object ?random_epi.so? not found
    Error: loading failed
    Execution halted
    ERROR: loading failed

    When I checked my src folder, there is only random_epi.o file. How can I
    fix this issue? Any help would be much appreciated. I'm vey new to both R
    and Fortran coding, especially in package building.

    Thanks in advance!
    Vineetha


    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org <mailto:r-help@r-project.org> mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help <https://stat.ethz.ch/mailman/listinfo/r-help>
    PLEASE do read the posting guide http://www.R-project.org/posting-guide.html <http://www.r-project.org/posting-guide.html>
    and provide commented, minimal, self-contained, reproducible code.



      [[alternative HTML version deleted]]
  • William Dunlap at Jun 16, 2016 at 5:54 pm
    1: .Fortran("dataxy", n = as.integer(n), tmax = as.integer(tmax),
      alpha = as.double(alpha), beta = as.double(beta), x = as.double(0,
      length = n), y = as.double(0, length = n), tau = as.integer(0,
      length = n))


    Are you expecting that
         as.integer(0, length=n)
    and
         as.double(0, length = n)
    will produce vectors of length 'n'? They do not and short inputs will
    usually
    cause memory misuse and crashes in the Fortran code.






    Bill Dunlap
    TIBCO Software
    wdunlap tibco.com


    On Thu, Jun 16, 2016 at 10:03 AM, Kodalore Vijayan, Vineetha W wrote:

    Hi Eduardo,

    Thanks for your comments. I haven't tried the way you told me. Now when I
    tried, got the following error:

    *** caught segfault ***
    address 0x0, cause 'memory not mapped'

    Traceback:
    1: .Fortran("dataxy", n = as.integer(n), tmax = as.integer(tmax),
    alpha = as.double(alpha), beta = as.double(beta), x = as.double(0,
    length = n), y = as.double(0, length = n), tau = as.integer(0,
    length = n))
    2: out(NULL, NULL, NULL, NULL)

    Possible actions:
    1: abort (with core dump, if enabled)
    2: normal R exit
    3: exit R without saving workspace
    4: exit R saving workspace
    Selection:

    Any suggestions?

    Thanks,
    Vineetha

    On Wed, Jun 15, 2016 at 3:55 PM, Eduardo M. A. M.Mendes <
    emammendes at gmail.com> wrote:
    Hi

    Have you tried to load and run the fortran code using just a wrapper
    function in R? I do that as the first step in order to build a package.

    Example: fortran sources -> rk4_mod_r.f90 ,derive_henonheilles.f90,
    poincare_section.f90

    a) I use R CMD SHLIB rk4_mod_r.f90 ,derive_henonheilles.f90,
    poincare_section.f90 - o poincare_section_henonheilles_rk4.so
    b) Then I write a wrapper function in R, poinc_section_henonheilles.R
    ...
    dyn.load("poincare_section_henonheilles_rk4.so")

    out<-.Fortran("section_crossing",
    h=as.numeric(h),
    nphas=as.integer(nphas),..
    ...
    c) and call the function as usual.

    Please note that the function called by .Fortran is the name of the
    subroutine within poincare_section.f90 and not the filename.

    I take the opportunity to thank R-developers for making the calling of C
    and Fortran in R very easy.

    I hope this helps.

    regards

    Ed

    PS. If you need an example of a package using Fortran90, please check
    https://github.com/emammendes/mittagleffler



    On Jun 15, 2016, at 5:20 PM, Kodalore Vijayan, Vineetha W <vwkv13 at mun.ca

    wrote:

    Hi,

    I'm trying to write an R package that calls a Fortran subroutine on my Mac
    os x El Capitan with Xcode 7 and gfortran 6.1, R 3.3.0. I can build and
    load the library but when I try to use it in R I get this error:

    library(NEpidemic)
    random_epi(variable_names)


    Error in .Fortran("random_epi", : "random_pi" not resolved from current
    namespace (NEpidemic).

    Then I tried adding useDynLib(random_epi.f95) in the NAMESPACE file,
    additional to useDynLib(NEpidemic). After doing that I couldn't build the
    package and it gave me another error:

    Error in library.dynam(lib, package, package.lib) :
    shared object ?random_epi.so? not found
    Error: loading failed
    Execution halted
    ERROR: loading failed

    When I checked my src folder, there is only random_epi.o file. How can I
    fix this issue? Any help would be much appreciated. I'm vey new to both R
    and Fortran coding, especially in package building.

    Thanks in advance!
    Vineetha

    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.

    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.

      [[alternative HTML version deleted]]
  • Kodalore Vijayan, Vineetha W at Jun 16, 2016 at 6:01 pm
    Hi,


    @Eduardo: I do have statements like, double preciosion :: y(n) in my
    fortran code. Will change the code and run again.


    @ William : Yes I was initializing X ,Y,and tau, each have a vector of
    length "n".


    Thanks,
    Vineetha


    On Thu, Jun 16, 2016 at 11:54 AM, William Dunlap wrote:

    1: .Fortran("dataxy", n = as.integer(n), tmax = as.integer(tmax),
    alpha = as.double(alpha), beta = as.double(beta), x = as.double(0,
    length = n), y = as.double(0, length = n), tau = as.integer(0,
    length = n))

    Are you expecting that
    as.integer(0, length=n)
    and
    as.double(0, length = n)
    will produce vectors of length 'n'? They do not and short inputs will
    usually
    cause memory misuse and crashes in the Fortran code.



    Bill Dunlap
    TIBCO Software
    wdunlap tibco.com

    On Thu, Jun 16, 2016 at 10:03 AM, Kodalore Vijayan, Vineetha W <
    vwkv13 at mun.ca> wrote:
    Hi Eduardo,

    Thanks for your comments. I haven't tried the way you told me. Now when I
    tried, got the following error:

    *** caught segfault ***
    address 0x0, cause 'memory not mapped'

    Traceback:
    1: .Fortran("dataxy", n = as.integer(n), tmax = as.integer(tmax),
    alpha = as.double(alpha), beta = as.double(beta), x = as.double(0,
    length = n), y = as.double(0, length = n), tau = as.integer(0,
    length = n))
    2: out(NULL, NULL, NULL, NULL)

    Possible actions:
    1: abort (with core dump, if enabled)
    2: normal R exit
    3: exit R without saving workspace
    4: exit R saving workspace
    Selection:

    Any suggestions?

    Thanks,
    Vineetha

    On Wed, Jun 15, 2016 at 3:55 PM, Eduardo M. A. M.Mendes <
    emammendes at gmail.com> wrote:
    Hi

    Have you tried to load and run the fortran code using just a wrapper
    function in R? I do that as the first step in order to build a package.
    Example: fortran sources -> rk4_mod_r.f90 ,derive_henonheilles.f90,
    poincare_section.f90

    a) I use R CMD SHLIB rk4_mod_r.f90 ,derive_henonheilles.f90,
    poincare_section.f90 - o poincare_section_henonheilles_rk4.so
    b) Then I write a wrapper function in R, poinc_section_henonheilles.R
    ...
    dyn.load("poincare_section_henonheilles_rk4.so")

    out<-.Fortran("section_crossing",
    h=as.numeric(h),
    nphas=as.integer(nphas),..
    ...
    c) and call the function as usual.

    Please note that the function called by .Fortran is the name of the
    subroutine within poincare_section.f90 and not the filename.

    I take the opportunity to thank R-developers for making the calling of C
    and Fortran in R very easy.

    I hope this helps.

    regards

    Ed

    PS. If you need an example of a package using Fortran90, please check
    https://github.com/emammendes/mittagleffler



    On Jun 15, 2016, at 5:20 PM, Kodalore Vijayan, Vineetha W <
    vwkv13 at mun.ca>
    wrote:

    Hi,

    I'm trying to write an R package that calls a Fortran subroutine on my Mac
    os x El Capitan with Xcode 7 and gfortran 6.1, R 3.3.0. I can build and
    load the library but when I try to use it in R I get this error:

    library(NEpidemic)
    random_epi(variable_names)


    Error in .Fortran("random_epi", : "random_pi" not resolved from current
    namespace (NEpidemic).

    Then I tried adding useDynLib(random_epi.f95) in the NAMESPACE file,
    additional to useDynLib(NEpidemic). After doing that I couldn't build the
    package and it gave me another error:

    Error in library.dynam(lib, package, package.lib) :
    shared object ?random_epi.so? not found
    Error: loading failed
    Execution halted
    ERROR: loading failed

    When I checked my src folder, there is only random_epi.o file. How can I
    fix this issue? Any help would be much appreciated. I'm vey new to both R
    and Fortran coding, especially in package building.

    Thanks in advance!
    Vineetha

    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.

    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.

      [[alternative HTML version deleted]]
  • Eduardo M. A. M.Mendes at Jun 16, 2016 at 6:02 pm
    Thanks Bill for pointing this out. I haven?t noticed it.


    Vineetha, try as.double(rep(0,n)) or as.matrix(rep(0,n)),


    Ed

    On Jun 16, 2016, at 2:54 PM, William Dunlap wrote:

    1: .Fortran("dataxy", n = as.integer(n), tmax = as.integer(tmax), alpha = as.double(alpha), beta = as.double(beta), x = as.double(0, length = n), y = as.double(0, length = n), tau = as.integer(0, length = n))
    Are you expecting that
    as.integer(0, length=n)
    and
    as.double(0, length = n)
    will produce vectors of length 'n'? They do not and short inputs will usually
    cause memory misuse and crashes in the Fortran code.



    Bill Dunlap
    TIBCO Software
    wdunlap tibco.com <http://tibco.com/>
    On Thu, Jun 16, 2016 at 10:03 AM, Kodalore Vijayan, Vineetha W <vwkv13 at mun.ca wrote:
    Hi Eduardo,

    Thanks for your comments. I haven't tried the way you told me. Now when I
    tried, got the following error:

    *** caught segfault ***
    address 0x0, cause 'memory not mapped'

    Traceback:
    1: .Fortran("dataxy", n = as.integer(n), tmax = as.integer(tmax),
    alpha = as.double(alpha), beta = as.double(beta), x = as.double(0,
    length = n), y = as.double(0, length = n), tau = as.integer(0,
    length = n))
    2: out(NULL, NULL, NULL, NULL)

    Possible actions:
    1: abort (with core dump, if enabled)
    2: normal R exit
    3: exit R without saving workspace
    4: exit R saving workspace
    Selection:

    Any suggestions?

    Thanks,
    Vineetha

    On Wed, Jun 15, 2016 at 3:55 PM, Eduardo M. A. M.Mendes <
    emammendes at gmail.com wrote:
    Hi

    Have you tried to load and run the fortran code using just a wrapper
    function in R? I do that as the first step in order to build a package.

    Example: fortran sources -> rk4_mod_r.f90 ,derive_henonheilles.f90,
    poincare_section.f90

    a) I use R CMD SHLIB rk4_mod_r.f90 ,derive_henonheilles.f90,
    poincare_section.f90 - o poincare_section_henonheilles_rk4.so
    b) Then I write a wrapper function in R, poinc_section_henonheilles.R
    ...
    dyn.load("poincare_section_henonheilles_rk4.so")

    out<-.Fortran("section_crossing",
    h=as.numeric(h),
    nphas=as.integer(nphas),..
    ...
    c) and call the function as usual.

    Please note that the function called by .Fortran is the name of the
    subroutine within poincare_section.f90 and not the filename.

    I take the opportunity to thank R-developers for making the calling of C
    and Fortran in R very easy.

    I hope this helps.

    regards

    Ed

    PS. If you need an example of a package using Fortran90, please check
    https://github.com/emammendes/mittagleffler <https://github.com/emammendes/mittagleffler>



    On Jun 15, 2016, at 5:20 PM, Kodalore Vijayan, Vineetha W <vwkv13 at mun.ca <mailto:vwkv13@mun.ca>>
    wrote:

    Hi,

    I'm trying to write an R package that calls a Fortran subroutine on my Mac
    os x El Capitan with Xcode 7 and gfortran 6.1, R 3.3.0. I can build and
    load the library but when I try to use it in R I get this error:

    library(NEpidemic)
    random_epi(variable_names)


    Error in .Fortran("random_epi", : "random_pi" not resolved from current
    namespace (NEpidemic).

    Then I tried adding useDynLib(random_epi.f95) in the NAMESPACE file,
    additional to useDynLib(NEpidemic). After doing that I couldn't build the
    package and it gave me another error:

    Error in library.dynam(lib, package, package.lib) :
    shared object ?random_epi.so? not found
    Error: loading failed
    Execution halted
    ERROR: loading failed

    When I checked my src folder, there is only random_epi.o file. How can I
    fix this issue? Any help would be much appreciated. I'm vey new to both R
    and Fortran coding, especially in package building.

    Thanks in advance!
    Vineetha

    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org <mailto:r-help@r-project.org> mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help <https://stat.ethz.ch/mailman/listinfo/r-help>
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html <http://www.r-project.org/posting-guide.html>
    and provide commented, minimal, self-contained, reproducible code.

    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org <mailto:r-help@r-project.org> mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help <https://stat.ethz.ch/mailman/listinfo/r-help>
    PLEASE do read the posting guide http://www.R-project.org/posting-guide.html <http://www.r-project.org/posting-guide.html>
    and provide commented, minimal, self-contained, reproducible code.



      [[alternative HTML version deleted]]
  • Kodalore Vijayan, Vineetha W at Jun 16, 2016 at 6:17 pm
    Hi,


      Its running in R separately using dyn.load(). Thanks!


      But my original issue is still there. I still can not build my package. My
    source code file name in SRC folder is "randomepi.f95" , the package name
    is "NEpidemic". and the wrapper function in the R folder is "randomepi.r".
    Not sure if I have to give the same file names.


    $R CMD BUILD NEpidemic

    Error in library.dynam(lib, package, package.lib) :
        shared object ?randomepi.so? not found
        Error: loading failed


    My namespace file has the following:


    exportPattern("^[[:alpha:]]+")
    export(randomepi)
    useDynLib(randomepi)
    import(graphics,grDevices,stats, utils)




    Thanks,
    Vineetha




    On Thu, Jun 16, 2016 at 12:02 PM, Eduardo M. A. M.Mendes wrote:

    Thanks Bill for pointing this out. I haven?t noticed it.

    Vineetha, try as.double(rep(0,n)) or as.matrix(rep(0,n)),

    Ed
    On Jun 16, 2016, at 2:54 PM, William Dunlap wrote:

    1: .Fortran("dataxy", n = as.integer(n), tmax = as.integer(tmax),
    alpha = as.double(alpha), beta = as.double(beta), x = as.double(0,
    length = n), y = as.double(0, length = n), tau = as.integer(0,
    length = n))

    Are you expecting that
    as.integer(0, length=n)
    and
    as.double(0, length = n)
    will produce vectors of length 'n'? They do not and short inputs will
    usually
    cause memory misuse and crashes in the Fortran code.



    Bill Dunlap
    TIBCO Software
    wdunlap tibco.com

    On Thu, Jun 16, 2016 at 10:03 AM, Kodalore Vijayan, Vineetha W <
    vwkv13 at mun.ca> wrote:
    Hi Eduardo,

    Thanks for your comments. I haven't tried the way you told me. Now when I
    tried, got the following error:

    *** caught segfault ***
    address 0x0, cause 'memory not mapped'

    Traceback:
    1: .Fortran("dataxy", n = as.integer(n), tmax = as.integer(tmax),
    alpha = as.double(alpha), beta = as.double(beta), x = as.double(0,
    length = n), y = as.double(0, length = n), tau = as.integer(0,
    length = n))
    2: out(NULL, NULL, NULL, NULL)

    Possible actions:
    1: abort (with core dump, if enabled)
    2: normal R exit
    3: exit R without saving workspace
    4: exit R saving workspace
    Selection:

    Any suggestions?

    Thanks,
    Vineetha

    On Wed, Jun 15, 2016 at 3:55 PM, Eduardo M. A. M.Mendes <
    emammendes at gmail.com> wrote:
    Hi

    Have you tried to load and run the fortran code using just a wrapper
    function in R? I do that as the first step in order to build a package.
    Example: fortran sources -> rk4_mod_r.f90 ,derive_henonheilles.f90,
    poincare_section.f90

    a) I use R CMD SHLIB rk4_mod_r.f90 ,derive_henonheilles.f90,
    poincare_section.f90 - o poincare_section_henonheilles_rk4.so
    b) Then I write a wrapper function in R, poinc_section_henonheilles.R
    ...
    dyn.load("poincare_section_henonheilles_rk4.so")

    out<-.Fortran("section_crossing",
    h=as.numeric(h),
    nphas=as.integer(nphas),..
    ...
    c) and call the function as usual.

    Please note that the function called by .Fortran is the name of the
    subroutine within poincare_section.f90 and not the filename.

    I take the opportunity to thank R-developers for making the calling of C
    and Fortran in R very easy.

    I hope this helps.

    regards

    Ed

    PS. If you need an example of a package using Fortran90, please check
    https://github.com/emammendes/mittagleffler



    On Jun 15, 2016, at 5:20 PM, Kodalore Vijayan, Vineetha W <
    vwkv13 at mun.ca>
    wrote:

    Hi,

    I'm trying to write an R package that calls a Fortran subroutine on my Mac
    os x El Capitan with Xcode 7 and gfortran 6.1, R 3.3.0. I can build and
    load the library but when I try to use it in R I get this error:

    library(NEpidemic)
    random_epi(variable_names)


    Error in .Fortran("random_epi", : "random_pi" not resolved from current
    namespace (NEpidemic).

    Then I tried adding useDynLib(random_epi.f95) in the NAMESPACE file,
    additional to useDynLib(NEpidemic). After doing that I couldn't build the
    package and it gave me another error:

    Error in library.dynam(lib, package, package.lib) :
    shared object ?random_epi.so? not found
    Error: loading failed
    Execution halted
    ERROR: loading failed

    When I checked my src folder, there is only random_epi.o file. How can I
    fix this issue? Any help would be much appreciated. I'm vey new to both R
    and Fortran coding, especially in package building.

    Thanks in advance!
    Vineetha

    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    <http://www.r-project.org/posting-guide.html>
    and provide commented, minimal, self-contained, reproducible code.

    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    <http://www.r-project.org/posting-guide.html>
    and provide commented, minimal, self-contained, reproducible code.


      [[alternative HTML version deleted]]
  • Kodalore Vijayan, Vineetha W at Jun 16, 2016 at 9:27 pm
    Thanks for the comment. It resolved now. I have edited my namespace file.
    -V


    On Thu, Jun 16, 2016 at 3:20 PM, Uwe Ligges wrote:

    On 16.06.2016 20:17, Kodalore Vijayan, Vineetha W wrote:

    Hi,

    Its running in R separately using dyn.load(). Thanks!

    But my original issue is still there. I still can not build my package.
    My
    source code file name in SRC folder is "randomepi.f95" , the package name
    is "NEpidemic". and the wrapper function in the R folder is "randomepi.r".
    Not sure if I have to give the same file names.

    $R CMD BUILD NEpidemic

    Error in library.dynam(lib, package, package.lib) :
    shared object ?randomepi.so? not found
    Error: loading failed

    My namespace file has the following:

    exportPattern("^[[:alpha:]]+")
    export(randomepi)
    useDynLib(randomepi)
    You probably need
    useDynLib(NEpidemic)
    since the package mechanism will build a NEpidemic.so

    Best,
    Uwe Ligges



    import(graphics,grDevices,stats, utils)

    Thanks,
    Vineetha


    On Thu, Jun 16, 2016 at 12:02 PM, Eduardo M. A. M.Mendes <
    emammendes at gmail.com> wrote:

    Thanks Bill for pointing this out. I haven?t noticed it.
    Vineetha, try as.double(rep(0,n)) or as.matrix(rep(0,n)),

    Ed

    On Jun 16, 2016, at 2:54 PM, William Dunlap wrote:

    1: .Fortran("dataxy", n = as.integer(n), tmax = as.integer(tmax),
    alpha = as.double(alpha), beta = as.double(beta), x = as.double(0,
    length = n), y = as.double(0, length = n), tau = as.integer(0,
    length = n))

    Are you expecting that
    as.integer(0, length=n)
    and
    as.double(0, length = n)
    will produce vectors of length 'n'? They do not and short inputs will
    usually
    cause memory misuse and crashes in the Fortran code.



    Bill Dunlap
    TIBCO Software
    wdunlap tibco.com

    On Thu, Jun 16, 2016 at 10:03 AM, Kodalore Vijayan, Vineetha W <
    vwkv13 at mun.ca> wrote:

    Hi Eduardo,
    Thanks for your comments. I haven't tried the way you told me. Now
    when I
    tried, got the following error:

    *** caught segfault ***
    address 0x0, cause 'memory not mapped'

    Traceback:
    1: .Fortran("dataxy", n = as.integer(n), tmax = as.integer(tmax),
    alpha = as.double(alpha), beta = as.double(beta), x = as.double(0,
    length = n), y = as.double(0, length = n), tau = as.integer(0,
    length = n))
    2: out(NULL, NULL, NULL, NULL)

    Possible actions:
    1: abort (with core dump, if enabled)
    2: normal R exit
    3: exit R without saving workspace
    4: exit R saving workspace
    Selection:

    Any suggestions?

    Thanks,
    Vineetha

    On Wed, Jun 15, 2016 at 3:55 PM, Eduardo M. A. M.Mendes <
    emammendes at gmail.com> wrote:

    Hi
    Have you tried to load and run the fortran code using just a wrapper
    function in R? I do that as the first step in order to build a package.
    Example: fortran sources -> rk4_mod_r.f90 ,derive_henonheilles.f90,
    poincare_section.f90

    a) I use R CMD SHLIB rk4_mod_r.f90 ,derive_henonheilles.f90,
    poincare_section.f90 - o poincare_section_henonheilles_rk4.so
    b) Then I write a wrapper function in R, poinc_section_henonheilles.R
    ...
    dyn.load("poincare_section_henonheilles_rk4.so")

    out<-.Fortran("section_crossing",
    h=as.numeric(h),
    nphas=as.integer(nphas),..
    ...
    c) and call the function as usual.

    Please note that the function called by .Fortran is the name of the
    subroutine within poincare_section.f90 and not the filename.

    I take the opportunity to thank R-developers for making the calling of
    C
    and Fortran in R very easy.

    I hope this helps.

    regards

    Ed

    PS. If you need an example of a package using Fortran90, please check
    https://github.com/emammendes/mittagleffler



    On Jun 15, 2016, at 5:20 PM, Kodalore Vijayan, Vineetha W <
    vwkv13 at mun.ca>
    wrote:

    Hi,

    I'm trying to write an R package that calls a Fortran subroutine on my Mac
    os x El Capitan with Xcode 7 and gfortran 6.1, R 3.3.0. I can build and
    load the library but when I try to use it in R I get this error:

    library(NEpidemic)
    random_epi(variable_names)


    Error in .Fortran("random_epi", : "random_pi" not resolved from current
    namespace (NEpidemic).

    Then I tried adding useDynLib(random_epi.f95) in the NAMESPACE file,
    additional to useDynLib(NEpidemic). After doing that I couldn't build the
    package and it gave me another error:

    Error in library.dynam(lib, package, package.lib) :
    shared object ?random_epi.so? not found
    Error: loading failed
    Execution halted
    ERROR: loading failed

    When I checked my src folder, there is only random_epi.o file. How can I
    fix this issue? Any help would be much appreciated. I'm vey new to both R
    and Fortran coding, especially in package building.

    Thanks in advance!
    Vineetha

    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    <http://www.r-project.org/posting-guide.html>
    and provide commented, minimal, self-contained, reproducible code.


    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    <http://www.r-project.org/posting-guide.html>
    and provide commented, minimal, self-contained, reproducible code.


    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.

      [[alternative HTML version deleted]]
  • Berend Hasselman at Jun 16, 2016 at 6:50 pm

    On 16 Jun 2016, at 20:02, Eduardo M. A. M.Mendes wrote:

    Thanks Bill for pointing this out. I haven?t noticed it.

    Vineetha, try as.double(rep(0,n)) or as.matrix(rep(0,n)),

    Why not simply numeric(n)?


    Berend Hasselman
  • Eduardo M. A. M.Mendes at Jun 16, 2016 at 7:04 pm

    On Jun 16, 2016, at 3:50 PM, Berend Hasselman wrote:

    On 16 Jun 2016, at 20:02, Eduardo M. A. M.Mendes wrote:

    Thanks Bill for pointing this out. I haven?t noticed it.

    Vineetha, try as.double(rep(0,n)) or as.matrix(rep(0,n)),
    Why not simply numeric(n)?

    Berend Hasselman

    as.numeric(rep(0,n)) works too. Please remember that he wants a vector nor a scalar.
  • Berend Hasselman at Jun 16, 2016 at 7:19 pm

    On 16 Jun 2016, at 21:04, Eduardo M. A. M.Mendes wrote:

    On Jun 16, 2016, at 3:50 PM, Berend Hasselman wrote:

    On 16 Jun 2016, at 20:02, Eduardo M. A. M.Mendes wrote:

    Thanks Bill for pointing this out. I haven?t noticed it.

    Vineetha, try as.double(rep(0,n)) or as.matrix(rep(0,n)),
    Why not simply numeric(n)?

    Berend Hasselman
    as.numeric(rep(0,n)) works too. Please remember that he wants a vector nor a scalar.

    Indeed it does. And I certainly remembered that the OP wants a vector of length n.
    But so does numeric(n), which creates a length n vector. Just try numeric(2).


    Berend
  • Kodalore Vijayan, Vineetha W at Jun 16, 2016 at 7:31 pm
    Thanks for the suggestion Berend. I just tried with numeric(n) and its
    working for x and y.


    But my issue is different and its not resolved yet.


    -Vineetha


    On Thu, Jun 16, 2016 at 1:19 PM, Berend Hasselman wrote:

    On 16 Jun 2016, at 21:04, Eduardo M. A. M.Mendes wrote:

    On Jun 16, 2016, at 3:50 PM, Berend Hasselman wrote:

    On 16 Jun 2016, at 20:02, Eduardo M. A. M.Mendes wrote:

    Thanks Bill for pointing this out. I haven?t noticed it.

    Vineetha, try as.double(rep(0,n)) or as.matrix(rep(0,n)),
    Why not simply numeric(n)?

    Berend Hasselman
    as.numeric(rep(0,n)) works too. Please remember that he wants a vector
    nor a scalar.
    Indeed it does. And I certainly remembered that the OP wants a vector of
    length n.
    But so does numeric(n), which creates a length n vector. Just try
    numeric(2).

    Berend

      [[alternative HTML version deleted]]
  • MacQueen, Don at Jun 16, 2016 at 4:36 pm
    You might want to take this question to R-sig-mac.


    --
    Don MacQueen


    Lawrence Livermore National Laboratory
    7000 East Ave., L-627
    Livermore, CA 94550
    925-423-1062










    On 6/15/16, 1:20 PM, "R-help on behalf of Kodalore Vijayan, Vineetha W"
    <r-help-bounces@r-project.org on behalf of vwkv13@mun.ca> wrote:

    Hi,

    I'm trying to write an R package that calls a Fortran subroutine on my
    Mac
    os x El Capitan with Xcode 7 and gfortran 6.1, R 3.3.0. I can build and
    load the library but when I try to use it in R I get this error:
    library(NEpidemic)
    random_epi(variable_names)
    Error in .Fortran("random_epi", : "random_pi" not resolved from current
    namespace (NEpidemic).

    Then I tried adding useDynLib(random_epi.f95) in the NAMESPACE file,
    additional to useDynLib(NEpidemic). After doing that I couldn't build the
    package and it gave me another error:

    Error in library.dynam(lib, package, package.lib) :
    shared object ?random_epi.so? not found
    Error: loading failed
    Execution halted
    ERROR: loading failed

    When I checked my src folder, there is only random_epi.o file. How can I
    fix this issue? Any help would be much appreciated. I'm vey new to both R
    and Fortran coding, especially in package building.

    Thanks in advance!
    Vineetha

    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.
  • Kodalore Vijayan, Vineetha W at Jun 16, 2016 at 7:33 pm
    Thank you Don. I did send an email to R-sig-mac.


    -Vineetha


    On Thu, Jun 16, 2016 at 10:36 AM, MacQueen, Don wrote:

    You might want to take this question to R-sig-mac.

    --
    Don MacQueen

    Lawrence Livermore National Laboratory
    7000 East Ave., L-627
    Livermore, CA 94550
    925-423-1062





    On 6/15/16, 1:20 PM, "R-help on behalf of Kodalore Vijayan, Vineetha W"
    <r-help-bounces@r-project.org on behalf of vwkv13@mun.ca> wrote:

    Hi,

    I'm trying to write an R package that calls a Fortran subroutine on my
    Mac
    os x El Capitan with Xcode 7 and gfortran 6.1, R 3.3.0. I can build and
    load the library but when I try to use it in R I get this error:
    library(NEpidemic)
    random_epi(variable_names)
    Error in .Fortran("random_epi", : "random_pi" not resolved from current
    namespace (NEpidemic).

    Then I tried adding useDynLib(random_epi.f95) in the NAMESPACE file,
    additional to useDynLib(NEpidemic). After doing that I couldn't build the
    package and it gave me another error:

    Error in library.dynam(lib, package, package.lib) :
    shared object ?random_epi.so? not found
    Error: loading failed
    Execution halted
    ERROR: loading failed

    When I checked my src folder, there is only random_epi.o file. How can I
    fix this issue? Any help would be much appreciated. I'm vey new to both R
    and Fortran coding, especially in package building.

    Thanks in advance!
    Vineetha

    [[alternative HTML version deleted]]

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.

      [[alternative HTML version deleted]]

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupr-help @
categoriesr
postedJun 15, '16 at 8:20p
activeJun 16, '16 at 9:27p
posts15
users5
websiter-project.org
irc#r

People

Translate

site design / logo © 2017 Grokbase