[Rd] for help on building a R package with several R function and a bunch of c, c++
Hope I can get quick help from here, I have a bunch of c, c++ included main function and makefile. It works well on both UNIX and windows. I tried to build R package which include this C++ program and several other R functions. These R function here are independent of c++ code. I prefer to define one R function to call this c++ program (main function). I know how to build R package with just R function, but I don't know how to handle those c++ c code after I copied those code in ./src, I am reading manual "Writing R Extensions" , but I did n't catch the key point . Do you know any easy way to do it? , Thank you in advance! Alex __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] for help on building a R package with several R function and a bunch of c, c++
Hope I can get quick help from here, I have a bunch of c, c++ included main function and makefile. It works well on both UNIX and windows. I tried to build R package which include this C++ program and several other R functions. These R functions here are independent of c++ code. I prefer to define one R function to call this c++ program. I know how to build R package with just R function, But I don't know how to handle those c++, c and makefile after I copied them in /src. I am reading manual "Writing R Extensions", I didn't catch the key point . Do you guys anybody know easy way to do it?. Thank you in advance! Alex __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] for help on building a R package with several R function and a bunch of c, c++
On 5 March 2010 at 13:15, alex46...@yahoo.com wrote: | Hope I can get quick help from here, I have a bunch of c, c++ included main function and makefile. It works well on both UNIX and windows. I tried to build R package which include this C++ program and several other R functions. These R function here are independent of c++ code. I prefer to define one R function to call this c++ program (main function). | | I know how to build R package with just R function, but I don't know how to handle those c++ c code after I copied those code in ./src, I am reading manual "Writing R Extensions" , but I did n't catch the key point . Do you know any easy way to do it? , When you asked _that exact same question_ this morning on r-help, you got the following answer: From: Whit Armstrong To: alex46...@yahoo.com Cc: r-h...@r-project.org Subject: Re: [R] for help on building a R package with several R function and a bunch of c, c++ Date: Fri, 5 Mar 2010 10:33:54 -0500 Pick up Rcpp, make your life easier. http://dirk.eddelbuettel.com/code/rcpp.html -Whit On Fri, Mar 5, 2010 at 9:19 AM, wrote: > Hope I can get quick help from here, I have a bunch of c, c++ included main function and makefile. It works well on both UNIX and windows. I tried to build R package which include this C++ program and several other R functions. R function here are independent c++ code. I prefer to define one R function to call this c++ program. > > Do you know any easy way to do it? I am reading manual "Writing R Extensions", I didn't catch the key point. I know how to build R package with just R function, If I put all c++ code and makefile in /src...what I need do? > > Thank you in advance! > > Alex Now, can you let us know a) what part of the answer was unclear to you, and b) what made you think you needed to repost _the identical question_ here | Thank you in advance! You're welcome. Dirk | Alex | | __ | R-devel@r-project.org mailing list | https://stat.ethz.ch/mailman/listinfo/r-devel -- Registration is open for the 2nd International conference R / Finance 2010 See http://www.RinFinance.com for details, and see you in Chicago in April! __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] for help on building a R package with several R function and a bunch of c, c++
I think the first question should be how to build a R function to call a bunch of C ,C++ which include one main program, and a makefile. My goal to build a R package will be next step. I read Rcpp , I am not sure if RcppResultSet can solve my problem or other function. Once I make sure it work I need ask UNIX adminstrator to install it. I think it shouldn't be very complex, as I know to build a R function easy with one C function. Thanks you for yout attention! Alex --- On Fri, 3/5/10, Dirk Eddelbuettel wrote: From: Dirk Eddelbuettel Subject: Re: [Rd] for help on building a R package with several R function and a bunch of c, c++ To: alex46...@yahoo.com Cc: r-devel@r-project.org Date: Friday, March 5, 2010, 8:25 PM On 5 March 2010 at 13:15, alex46...@yahoo.com wrote: | Hope I can get quick help from here, I have a bunch of c, c++ included main function and makefile. It works well on both UNIX and windows. I tried to build R package which include this C++ program and several other R functions. These R function here are independent of c++ code. I prefer to define one R function to call this c++ program (main function). | | I know how to build R package with just R function, but I don't know how to handle those c++ c code after I copied those code in ./src, I am reading manual "Writing R Extensions" , but I did n't catch the key point . Do you know any easy way to do it? , When you asked _that exact same question_ this morning on r-help, you got the following answer: From: Whit Armstrong To: alex46...@yahoo.com Cc: r-h...@r-project.org Subject: Re: [R] for help on building a R package with several R function and a bunch of c, c++ Date: Fri, 5 Mar 2010 10:33:54 -0500 Pick up Rcpp, make your life easier. http://dirk.eddelbuettel.com/code/rcpp.html -Whit On Fri, Mar 5, 2010 at 9:19 AM, wrote: > Hope I can get quick help from here, I have a bunch of c, c++ included main function and makefile. It works well on both UNIX and windows. I tried to build R package which include this C++ program and several other R functions. R function here are independent c++ code. I prefer to define one R function to call this c++ program. > > Do you know any easy way to do it? I am reading manual "Writing R Extensions", I didn't catch the key point. I know how to build R package with just R function, If I put all c++ code and makefile in /src...what I need do? > > Thank you in advance! > > Alex Now, can you let us know a) what part of the answer was unclear to you, and b) what made you think you needed to repost _the identical question_ here | Thank you in advance! You're welcome. Dirk | Alex | | __ | R-devel@r-project.org mailing list | https://stat.ethz.ch/mailman/listinfo/r-devel -- Registration is open for the 2nd International conference R / Finance 2010 See http://www.RinFinance.com for details, and see you in Chicago in April! [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] for help on building a R package with several R function and a bunch of c, c++
On 03/06/2010 03:27 AM, alex46...@yahoo.com wrote: I think the first question should be how to build a R function to call a bunch of C ,C++ which include one main program, and a makefile. My goal to build a R package will be next step. You should jump straight to making a package. You are making you life difficult with this "main program & makefile" model. Install Rcpp and try to use the Rcpp.package.skeleton, this will create a simple package that uses some C++ classes from Rcpp, as well as an R function that calls them. I read Rcpp , I am not sure if RcppResultSet can solve my problem or other function. Once I make sure it work I need ask UNIX adminstrator to install it. We don't know what your problem is. We can answer a question, but we cannot guess the question for you. Rcpp works, please refer to our unit tests, for example look at this vignette: http://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-unitTests.pdf I think it shouldn't be very complex, as I know to build a R function easy with one C function. Thanks you for yout attention! Alex --- On Fri, 3/5/10, Dirk Eddelbuettel wrote: From: Dirk Eddelbuettel Subject: Re: [Rd] for help on building a R package with several R function and a bunch of c, c++ To: alex46...@yahoo.com Cc: r-devel@r-project.org Date: Friday, March 5, 2010, 8:25 PM On 5 March 2010 at 13:15, alex46...@yahoo.com wrote: | Hope I can get quick help from here, I have a bunch of c, c++ included main function and makefile. It works well on both UNIX and windows. I tried to build R package which include this C++ program and several other R functions. These R function here are independent of c++ code. I prefer to define one R function to call this c++ program (main function). | | I know how to build R package with just R function, but I don't know how to handle those c++ c code after I copied those code in ./src, I am reading manual "Writing R Extensions" , but I did n't catch the key point . Do you know any easy way to do it? , When you asked _that exact same question_ this morning on r-help, you got the following answer: From: Whit Armstrong To: alex46...@yahoo.com Cc: r-h...@r-project.org Subject: Re: [R] for help on building a R package with several R function and a bunch of c, c++ Date: Fri, 5 Mar 2010 10:33:54 -0500 Pick up Rcpp, make your life easier. http://dirk.eddelbuettel.com/code/rcpp.html -Whit On Fri, Mar 5, 2010 at 9:19 AM, wrote: > Hope I can get quick help from here, I have a bunch of c, c++ included main function and makefile. It works well on both UNIX and windows. I tried to build R package which include this C++ program and several other R functions. R function here are independent c++ code. I prefer to define one R function to call this c++ program. > > Do you know any easy way to do it? I am reading manual "Writing R Extensions", I didn't catch the key point. I know how to build R package with just R function, If I put all c++ code and makefile in /src...what I need do? > > Thank you in advance! > > Alex Now, can you let us know a) what part of the answer was unclear to you, and b) what made you think you needed to repost _the identical question_ here | Thank you in advance! You're welcome. Dirk -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] for help on building a R package with several R function and a bunch of c, c++
Thank you for your help. So far what I did on my notebook as follows. My OS is windows7.  I downloaded Rcpp windows version, and load library("Rcpp") then.  1, Change main funnction to f1.cpp, remove makefile. 2 ,run Rcpp.package.skeleton(name="test",list=c("rec1.R","rect2.R")) 3, edit  /man, /R, copied my exist file whch I have done sucessfully without any c++ program before. 4, copy f1.cpp and all other related cpp and c into /src/ 5. Rcmd build --binary test  It showed--  making DLL gcc -lâC:/PROGRA~2/R/R-210~1.1/include",âC:/PROGRA~2/R/R-210~1.1/bin/Rscript -e' Rcpp:::CxxxFlags<>'` -03 -Wall -std =gnu -999 -c cranbombind.c -o cranbombind.o  gcc.exe: **\Documents/R/win-library/2.10/Rcpp/lib: No such file or directory... I checked the path, it did have C:\Users\alex **\Documents\R\win-library\2.10\Rcpp\lib  I don't know how I can fix the problem. do you think it could be problem there is a space between my first name and last name..  All I tried are on my own PC at home , I will tryon other  PC in my office.  Do you have suggestion?. Thanks,  Alex --- On Sun, 3/7/10, Romain Francois wrote: From: Romain Francois Subject: Re: [Rd] for help on building a R package with several R function and a bunch of c, c++ To: alex46...@yahoo.com Cc: "Dirk Eddelbuettel" , r-devel@r-project.org Date: Sunday, March 7, 2010, 3:59 AM On 03/06/2010 03:27 AM, alex46...@yahoo.com wrote: > I think the first question should be how to build a R function to call a > bunch of C ,C++ which include one main program, and a makefile. My goal to > build a R package will be next step. You should jump straight to making a package. You are making you life difficult with this "main program & makefile" model. Install Rcpp and try to use the Rcpp.package.skeleton, this will create a simple package that uses some C++ classes from Rcpp, as well as an R function that calls them. > I read Rcpp , I am not sure if RcppResultSet can solve my problem or other > function. Once I make sure it work I need ask UNIX adminstrator to install it. We don't know what your problem is. We can answer a question, but we cannot guess the question for you. Rcpp works, please refer to our unit tests, for example look at this vignette: http://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-unitTests.pdf > I think it shouldn't be very complex, as I know to build a R function easy > with one C function. > > Thanks you for yout attention! > > Alex > > --- On Fri, 3/5/10, Dirk Eddelbuettel wrote: > > > From: Dirk Eddelbuettel > Subject: Re: [Rd] for help on building a R package with several R function > and a bunch of c, c++ > To: alex46...@yahoo.com > Cc: r-devel@r-project.org > Date: Friday, March 5, 2010, 8:25 PM > > > > On 5 March 2010 at 13:15, alex46...@yahoo.com wrote: > | Hope I can get quick help from here, I have a bunch of c, c++ included main > function and makefile. It works well on both UNIX and windows. I tried to > build R package which include this C++ program and several other R > functions. These R function here are independent of c++ code. I prefer to > define one R function to call this c++ program (main function). > | > | I know how to build R package with just R function, but I don't know how to > handle those c++ c code after I copied those code in ./src, I am reading > manual "Writing R Extensions" , but I did n't catch the key point . Do you > know any easy way to do it? , > > When you asked _that exact same question_ this morning on r-help, you got the > following answer: > >    From: Whit Armstrong >    To: alex46...@yahoo.com >    Cc: r-h...@r-project.org >    Subject: Re: [R] for help on building a R package with several R >function and a bunch of c, c++ >    Date: Fri, 5 Mar 2010 10:33:54 -0500 > >    Pick up Rcpp, make your life easier. > >    http://dirk.eddelbuettel.com/code/rcpp.html > >    -Whit > >    On Fri, Mar 5, 2010 at 9:19 AM, wrote: >    > Hope I can get quick help from here, I have a bunch of c, c++ >included main function and makefile. It works well on both UNIX and windows. I >tried to build R package which include this C++ program and several other R >functions. R function here are independent c++ code. I prefer to define >one R function to call this c++ program. >    > >    > Do you know any easy way to do it? I am reading manual "Writing R >Extensions", I didn't catch the key point. I know how to build R package with >just R function, If I put all c++ code and makefile in /src...what I need do? >    > >
Re: [Rd] for help on building a R package with several R function and a bunch of c, c++
Hi, Yes, the problem is with spaces in path names. This has been fixed and will appear as Rcpp 0.7.8 in a few days. If you are in a rush, you can build it from svn, or quote the path that is returned from CxxFlags. Feel free to get back to us with more questions, although I'd encourage you to use the dedicated Rcpp-devel mailing list : https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel Romain On 03/08/2010 04:20 AM, alex46...@yahoo.com wrote: Thank you for your help. So far what I did on my notebook as follows. My OS is windows7.  I downloaded Rcpp windows version, and load library("Rcpp") then.  1, Change main funnction to f1.cpp, remove makefile. 2 ,run Rcpp.package.skeleton(name="test",list=c("rec1.R","rect2.R")) 3, edit  /man, /R, copied my exist file whch I have done sucessfully without any c++ program before. 4, copy f1.cpp and all other related cpp and c into /src/ 5. Rcmd build --binary test  It showed--  making DLL gcc -l“C:/PROGRA~2/R/R-210~1.1/include",“C:/PROGRA~2/R/R-210~1.1/bin/Rscript -e' Rcpp:::CxxxFlags<>'` -03 -Wall -std =gnu -999 -c cranbombind.c -o cranbombind.o  gcc.exe: **\Documents/R/win-library/2.10/Rcpp/lib: No such file or directory... I checked the path, it did have C:\Users\alex **\Documents\R\win-library\2.10\Rcpp\lib  I don't know how I can fix the problem. do you think it could be problem there is a space between my first name and last name..  All I tried are on my own PC at home , I will tryon other  PC in my office.  Do you have suggestion?. Thanks,  Alex --- On Sun, 3/7/10, Romain Francois wrote: From: Romain Francois Subject: Re: [Rd] for help on building a R package with several R function and a bunch of c, c++ To: alex46...@yahoo.com Cc: "Dirk Eddelbuettel", r-devel@r-project.org Date: Sunday, March 7, 2010, 3:59 AM On 03/06/2010 03:27 AM, alex46...@yahoo.com wrote: I think the first question should be how to build a R function to call a bunch of C ,C++ which include one main program, and a makefile. My goal to build a R package will be next step. You should jump straight to making a package. You are making you life difficult with this "main program& makefile" model. Install Rcpp and try to use the Rcpp.package.skeleton, this will create a simple package that uses some C++ classes from Rcpp, as well as an R function that calls them. I read Rcpp , I am not sure if RcppResultSet can solve my problem or other function. Once I make sure it work I need ask UNIX adminstrator to install it. We don't know what your problem is. We can answer a question, but we cannot guess the question for you. Rcpp works, please refer to our unit tests, for example look at this vignette: http://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-unitTests.pdf I think it shouldn't be very complex, as I know to build a R function easy with one C function. Thanks you for yout attention! Alex --- On Fri, 3/5/10, Dirk Eddelbuettel wrote: From: Dirk Eddelbuettel Subject: Re: [Rd] for help on building a R package with several R function and a bunch of c, c++ To: alex46...@yahoo.com Cc: r-devel@r-project.org Date: Friday, March 5, 2010, 8:25 PM On 5 March 2010 at 13:15, alex46...@yahoo.com wrote: | Hope I can get quick help from here, I have a bunch of c, c++ included main function and makefile. It works well on both UNIX and windows. I tried to build R package which include this C++ program and several other R functions. These R function here are independent of c++ code. I prefer to define one R function to call this c++ program (main function). | | I know how to build R package with just R function, but I don't know how to handle those c++ c code after I copied those code in ./src, I am reading manual "Writing R Extensions" , but I did n't catch the key point . Do you know any easy way to do it? , When you asked _that exact same question_ this morning on r-help, you got the following answer:     From: Whit Armstrong     To: alex46...@yahoo.com     Cc: r-h...@r-project.org     Subject: Re: [R] for help on building a R package with several R function and a bunch of c, c++     Date: Fri, 5 Mar 2010 10:33:54 -0500     Pick up Rcpp, make your life easier.     http://dirk.eddelbuettel.com/code/rcpp.html     -Whit     On Fri, Mar 5, 2010 at 9:19 AM, wrote:    Â> Hope I can get quick help from here, I have a bunch of c, c++ included main function and makefile. It works well on both UNIX and windows. I tried to build R package which include this C++ program and several other R functions. R function here are independent c++ code. I prefer to define one R function to call this c++ program.    Â>    Â> Do you know any easy way to do it? I am reading manual "Writing R E
Re: [Rd] for help on building a R package with several R function and a bunch of c, c++
I built R package with only R code before, this is first time I build R package with mixed R code and C, C++ code. I would try Rcpp on our center UNIX, before I ask the administrator to install it, I need confirm several issue are right. Thank you for you patient. 1, I change main function as a general function with certain name such as void tranptest(char* filename[], double* para[]), and copy this file and other related c, c++ h, program to /src, and removed makefile. 2, I noticed there is Makevars after I ran Rcpp.package.skeleton, do I need modify this file before I run R CMD build? what I need do for rcpp_hello_world.cpp rcpp_hello_world.cpp? it is template file handled by the program or it is for me to edit it as template? 3, Do I need write a R function such as tranptest<-function(inputfile, ctlfile,outfile, param1,param2,param3) { filenames<-c(inputfile,ctlfile,outfile) params<-as.vector(c(param1, param2,param3)) .C("tranptest", as.character(filenames),as.double(params)) } before I run R CMD build? if so, that means I put this R function in /R? 4, Do I need do anything to run library.dyname to load those complied objects? Where I can make sure it successful and I can use .C("tranptest",) in R before the wholepackage installed? Thank you so much! Alex --- On Mon, 3/8/10, Romain Francois wrote: > From: Romain Francois > Subject: Re: [Rd] for help on building a R package with several R function > and a bunch of c, c++ > To: alex46...@yahoo.com > Cc: r-devel@r-project.org, "Dirk Eddelbuettel" > Date: Monday, March 8, 2010, 2:47 AM > Hi, > > Yes, the problem is with spaces in path names. This has > been fixed and > will appear as Rcpp 0.7.8 in a few days. > > If you are in a rush, you can build it from svn, or quote > the path that > is returned from CxxFlags. > > Feel free to get back to us with more questions, although > I'd encourage > you to use the dedicated Rcpp-devel mailing list : > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel > > Romain > > On 03/08/2010 04:20 AM, alex46...@yahoo.com > wrote: > > Thank you for your help. So far what I did on > my notebook as follows. My OS is windows7. > >  > > I downloaded Rcpp windows version, and load > library("Rcpp") then. > >  > > 1, Change main funnction to f1.cpp, remove makefile. > > 2 ,run > Rcpp.package.skeleton(name="test",list=c("rec1.R","rect2.R")) > > 3, edit  /man, /R, copied my exist file whch I > have done sucessfully without any c++ program > before. > > 4, copy f1.cpp and all other related cpp and c > into /src/ > > 5. Rcmd build --binary test > >  > > It showed-- > >  > > making DLL > > gcc > -l“C:/PROGRA~2/R/R-210~1.1/include",“C:/PROGRA~2/R/R-210~1.1/bin/Rscript > -e' Rcpp:::CxxxFlags<>'` -03 -Wall -std =gnu -999 -c > cranbombind.c -o cranbombind.o > >  > > gcc.exe: **\Documents/R/win-library/2.10/Rcpp/lib: No > such file or directory... > > > > I checked the path, it did have C:\Users\alex > **\Documents\R\win-library\2.10\Rcpp\lib > >  > > I don't know how I can fix the problem. do you think > it could be problem there is a space between my first name > and last name.. > >  > > All I tried are on my own PC at home , I will tryon > other  PC in my office. > >  > > Do you have suggestion?. Thanks, > >  > > Alex > > --- On Sun, 3/7/10, Romain Francois > wrote: > > > > > > From: Romain Francois > > Subject: Re: [Rd] for help on building a R package > with several R function and a bunch of c, c++ > > To: alex46...@yahoo.com > > Cc: "Dirk Eddelbuettel", > r-devel@r-project.org > > Date: Sunday, March 7, 2010, 3:59 AM > > > > > > On 03/06/2010 03:27 AM, alex46...@yahoo.com > wrote: > >> I think the first question should be how to build > a R function to call a bunch of C ,C++ which include one > main program, and a makefile. My goal to build a R package > will be next step. > > > > You should jump straight to making a package. You are > making you life > > difficult with this "main program& makefile" > model. > > > > Install Rcpp and try to use the Rcpp.package.skeleton, > this will create > > a simple package that uses some C++ classes from Rcpp, > as well as an R > > function that calls them. > > > >> I read Rcpp , I am not sure if > RcppResultSet can solve my problem or other function. Once I > make sure it work I need ask UNIX adminstrator to install > it. >
Re: [Rd] for help on building a R package with several R function and a bunch of c, c++
Hello, On 03/08/2010 06:16 PM, alex46...@yahoo.com wrote: I built R package with only R code before, this is first time I build R package with mixed R code and C, C++ code. I would try Rcpp on our center UNIX, before I ask the administrator to install it, I need confirm several issue are right. Thank you for you patient. 1, I change main function as a general function with certain name such as void tranptest(char* filename[], double* para[]), and copy this file and other related c, c++ h, program to /src, and removed makefile. I'd encourage you to use the .Call interface, 2, I noticed there is Makevars after I ran Rcpp.package.skeleton, do I need modify this file before I run R CMD build? no what I need do for rcpp_hello_world.cpp rcpp_hello_world.cpp? it is template file handled by the program or it is for me to edit it as template? those are examples that we expand to show the kind of code you can write. feel free to dump them. In particular, it shows you how you declare c++ functions to be used by R: - The RcppExport prevents c++ mangling. see the rationale for this in writing R extensions. (RcppExport is just an alias for extern "C") - The function returns a SEXP (see writing R extensions) - The function takes zero or more SEXP as input (see writing R extensions) So I'd suggest you write your function something like this : RcppExport SEXP tranptest( SEXP filename_, SEXP para_){ Rcpp::CharacterVector filename( filename_ ) ; Rcpp::NumericVector para(para_) ; // use filename and para to do whatever you want to do with them // return something } 3, Do I need write a R function such as tranptest<-function(inputfile, ctlfile,outfile, param1,param2,param3) { filenames<-c(inputfile,ctlfile,outfile) params<-as.vector(c(param1, param2,param3)) .C("tranptest", as.character(filenames),as.double(params)) } before I run R CMD build? if so, that means I put this R function in /R? Again, I suggest you look into the .Call interface and go for something like this: .Call( "tranptest", filenames, params, PACKAGE = "yourpackage" ) 4, Do I need do anything to run library.dyname to load those complied objects? Where I can make sure it successful and I can use .C("tranptest",) in R before the wholepackage installed? Rcpp.package.skeleton adds a useDynLib directive to the NAMESPACE so you should be fine. Thank you so much! > Alex --- On Mon, 3/8/10, Romain Francois wrote: From: Romain Francois Subject: Re: [Rd] for help on building a R package with several R function and a bunch of c, c++ To: alex46...@yahoo.com Cc: r-devel@r-project.org, "Dirk Eddelbuettel" Date: Monday, March 8, 2010, 2:47 AM Hi, Yes, the problem is with spaces in path names. This has been fixed and will appear as Rcpp 0.7.8 in a few days. If you are in a rush, you can build it from svn, or quote the path that is returned from CxxFlags. Feel free to get back to us with more questions, although I'd encourage you to use the dedicated Rcpp-devel mailing list : https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel Romain On 03/08/2010 04:20 AM, alex46...@yahoo.com wrote: Thank you for your help. So far what I did on my notebook as follows. My OS is windows7.  I downloaded Rcpp windows version, and load library("Rcpp") then.  1, Change main funnction to f1.cpp, remove makefile. 2 ,run Rcpp.package.skeleton(name="test",list=c("rec1.R","rect2.R")) 3, edit  /man, /R, copied my exist file whch I have done sucessfully without any c++ program before. 4, copy f1.cpp and all other related cpp and c into /src/ 5. Rcmd build --binary test  It showed--  making DLL gcc -l“C:/PROGRA~2/R/R-210~1.1/include",“C:/PROGRA~2/R/R-210~1.1/bin/Rscript -e' Rcpp:::CxxxFlags<>'` -03 -Wall -std =gnu -999 -c cranbombind.c -o cranbombind.o  gcc.exe: **\Documents/R/win-library/2.10/Rcpp/lib: No such file or directory... I checked the path, it did have C:\Users\alex **\Documents\R\win-library\2.10\Rcpp\lib  I don't know how I can fix the problem. do you think it could be problem there is a space between my first name and last name..  All I tried are on my own PC at home , I will tryon other  PC in my office.  Do you have suggestion?. Thanks,  Alex --- On Sun, 3/7/10, Romain Francois wrote: From: Romain Francois Subject: Re: [Rd] for help on building a R package with several R function and a bunch of c, c++ To: alex46...@yahoo.com Cc: "Dirk Eddelbuettel", r-devel@r-project.org Date: Sunday, March 7, 2010, 3:59 AM On 03/06/2010 03:27 AM, alex46...@yahoo.com wrote: I think the first question should be how to build a R function to call a bunch of C ,C++ which include one main program, and a makefile. My goal to build a R package will be next step.
Re: [Rd] for help on building a R package with several R function and a bunch of c, c++
Alex, Can you _please_ stop spamming r-devel? Romain and I repeatedly pointed the existence of the rcpp-devel list out to you. Please consider using it. There are existing packages that use what you want to try use. I find it beneficial to start from a _working example_. Take e.g. the earthmovedist package on R-Forge, try to understand how it works and how it makes use of Rcpp and adapt your use case to what works. If it fails, send pointed messages with repeatable examples and clear error message to an appropriate list, eg rcpp-devel. Dirk -- Registration is open for the 2nd International conference R / Finance 2010 See http://www.RinFinance.com for details, and see you in Chicago in April! __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] for help on building a R package with several R function and a bunch of c, c++
Alex, On Mar 8, 2010, at 12:16 , alex46...@yahoo.com wrote: I built R package with only R code before, this is first time I build R package with mixed R code and C, C++ code. I would try Rcpp on our center UNIX, before I ask the administrator to install it, I need confirm several issue are right. Thank you for you patient. 1, I change main function as a general function with certain name such as void tranptest(char* filename[], double* para[]), and copy this file and other related c, c++ h, program to /src, and removed makefile. Yes, that's perfect - for the kind of usage you don't need Rcpp at all - R supports C++ sources out of the box. Just make sure your tranptest function is either in a .c file or you put extern "C" in front of it if it's in .cpp , e.g: foo.cpp: extern "C" void tranptest(char **fn, double *par) { ... } 2, I noticed there is Makevars after I ran Rcpp.package.skeleton, do I need modify this file before I run R CMD build? what I need do for rcpp_hello_world.cpp rcpp_hello_world.cpp? it is template file handled by the program or it is for me to edit it as template? 3, Do I need write a R function such as tranptest<- function(inputfile, ctlfile,outfile, param1,param2,param3) { filenames<-c(inputfile,ctlfile,outfile) params<-as.vector(c(param1, param2,param3)) .C("tranptest", as.character(filenames),as.double(params)) } before I run R CMD build? if so, that means I put this R function in /R? yes, in R/foo.R (replace "foo" by any name you want) 4, Do I need do anything to run library.dyname to load those complied objects? If you have a namespace just add useDynLib(foo) where "foo" is the name of your package. If you don't have a namespace (or don't kwno what that is ;)) just add a file R/zzz.R with the following content to your package: .First.lib <- function(libname, pkgname) library.dynam("foo", pkgname, libname) where "foo" is the name of your package. Where I can make sure it successful and I can use .C("tranptest",) in R before the wholepackage installed? It's really simple - you don't need to install the package to test it. Assuming "foo" is the name of your package: Build the sources: R CMD SHLIB -o foo.so *.c* start R in the same directory: R # load the library you just compiled dyn.load("foo.so") # test your code .C("tranptest", c("file1", "file2"), as.double(1,2,3,4)) Cheers, Simon Alex --- On Mon, 3/8/10, Romain Francois wrote: From: Romain Francois Subject: Re: [Rd] for help on building a R package with several R function and a bunch of c, c++ To: alex46...@yahoo.com Cc: r-devel@r-project.org, "Dirk Eddelbuettel" Date: Monday, March 8, 2010, 2:47 AM Hi, Yes, the problem is with spaces in path names. This has been fixed and will appear as Rcpp 0.7.8 in a few days. If you are in a rush, you can build it from svn, or quote the path that is returned from CxxFlags. Feel free to get back to us with more questions, although I'd encourage you to use the dedicated Rcpp-devel mailing list : https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel Romain On 03/08/2010 04:20 AM, alex46...@yahoo.com wrote: Thank you for your help. So far what I did on my notebook as follows. My OS is windows7.  I downloaded Rcpp windows version, and load library("Rcpp") then.  1, Change main funnction to f1.cpp, remove makefile. 2 ,run Rcpp.package.skeleton(name="test",list=c("rec1.R","rect2.R")) 3, edit  /man, /R, copied my exist file whch I have done sucessfully without any c++ program before. 4, copy f1.cpp and all other related cpp and c into /src/ 5. Rcmd build --binary test  It showed--  making DLL gcc -l“C:/PROGRA~2/R/R-210~1.1/include",“C:/PROGRA~2/R/R-210~1.1/ bin/Rscript -e' Rcpp:::CxxxFlags<>'` -03 -Wall -std =gnu -999 -c cranbombind.c -o cranbombind.o  gcc.exe: **\Documents/R/win-library/2.10/Rcpp/lib: No such file or directory... I checked the path, it did have C:\Users\alex **\Documents\R\win-library\2.10\Rcpp\lib  I don't know how I can fix the problem. do you think it could be problem there is a space between my first name and last name..  All I tried are on my own PC at home , I will tryon other  PC in my office.  Do you have suggestion?. Thanks,  Alex --- On Sun, 3/7/10, Romain Francois wrote: From: Romain Francois Subject: Re: [Rd] for help on building a R package with several R function and a bunch of c, c++ To: alex46...@yahoo.com Cc: "Dirk Eddelbuettel", r-devel@r-project.org Date: Sunday, March 7, 2010, 3:59 AM On 03/06/2010 03:27 AM, alex46...@yahoo.com wrote: I think the first question should be how to build a R function to call a bunch
Re: [Rd] for help on building a R package with several R function and a bunch of c, c++
Dirk, he was not asking about Rcpp originally - he was asking about C++. He seems to be reluctant to use Rcpp due to the complexities involved (for which I don't blame him) so going back to simple C++ basics of R- ext (which is what he was using in his example) is really R-devel topic I think ... Cheers, Simon On Mar 8, 2010, at 12:37 , Dirk Eddelbuettel wrote: Alex, Can you _please_ stop spamming r-devel? Romain and I repeatedly pointed the existence of the rcpp-devel list out to you. Please consider using it. There are existing packages that use what you want to try use. I find it beneficial to start from a _working example_. Take e.g. the earthmovedist package on R-Forge, try to understand how it works and how it makes use of Rcpp and adapt your use case to what works. If it fails, send pointed messages with repeatable examples and clear error message to an appropriate list, eg rcpp-devel. Dirk -- Registration is open for the 2nd International conference R / Finance 2010 See http://www.RinFinance.com for details, and see you in Chicago in April! __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] for help on building a R package with several R function and a bunch of c, c++
Yes! that is what I am looking for. When I post my question, I said I cannot catch the key point in "Writing R Extensions". Follow your suggestion, I almost have reached my goal although I passed the R CMD check mypackage. Before I install it (I need ask UNIX adminstrator to do it), I check the package, I got the information > dyn.load("tranptest.so") > filenames<-c("Mrklist.txt","CCdata.txt","outputfile") > param<-c(1,0,1,0,1,1) > .C("tranptest",as.character(filenames),as.double(param)) *** caught segfault *** address 0, cause 'memory not mapped' Traceback: 1: .C("tranptest",as.character(filenames), as.double(param)) Do you have any clue about the error? I think it is very close tothe end. Thank you so much . You save me a tons of time, Alex --- On Mon, 3/8/10, Simon Urbanek wrote: > From: Simon Urbanek > Subject: Re: [Rd] for help on building a R package with several R function > and a bunch of c, c++ > To: alex46...@yahoo.com > Cc: "Romain Francois" , r-devel@r-project.org, > "Dirk Eddelbuettel" > Date: Monday, March 8, 2010, 12:53 PM > Alex, > > On Mar 8, 2010, at 12:16 , alex46...@yahoo.com > wrote: > > > I built R package with only R code before, this is > first time I build R package with mixed R code and C, C++ > code. I would try Rcpp on our center UNIX, before I ask the > administrator to install it, I need confirm several issue > are right. Thank you for you patient. > > > > 1, I change main function as a general function with > certain name such as void tranptest(char* filename[], > double* para[]), and copy this file and other related c, > c++ h, program to /src, and removed makefile. > > > > Yes, that's perfect - for the kind of usage you don't need > Rcpp at all - R supports C++ sources out of the box. Just > make sure your tranptest function is either in a .c file or > you put > extern "C" > in front of it if it's in .cpp , e.g: > > foo.cpp: > extern "C" void tranptest(char **fn, double *par) { > ... > } > > > > 2, I noticed there is Makevars after I ran > Rcpp.package.skeleton, > > do I need modify this file before I run R CMD build? > what I need do for rcpp_hello_world.cpp > rcpp_hello_world.cpp? it is template file handled by the > program or it is for me to edit it as template? > > > > 3, Do I need write a R function such as > tranptest<-function(inputfile, ctlfile,outfile, > param1,param2,param3) > > { > > filenames<-c(inputfile,ctlfile,outfile) > > params<-as.vector(c(param1, param2,param3)) > > .C("tranptest", > as.character(filenames),as.double(params)) > > } > > before I run R CMD build? if so, that means I put this > R function in /R? > > > > yes, in R/foo.R (replace "foo" by any name you want) > > > > 4, Do I need do anything to run library.dyname to load > those complied objects? > > If you have a namespace just add > useDynLib(foo) > where "foo" is the name of your package. If you don't have > a namespace (or don't kwno what that is ;)) just add a file > R/zzz.R with the following content to your package: > .First.lib <- function(libname, pkgname) > library.dynam("foo", pkgname, libname) > where "foo" is the name of your package. > > > Where I can make sure it successful and I can use > .C("tranptest",) in R before the wholepackage > installed? > > > > It's really simple - you don't need to install the package > to test it. Assuming "foo" is the name of your package: > Build the sources: > R CMD SHLIB -o foo.so *.c* > > start R in the same directory: > R > # load the library you just compiled > dyn.load("foo.so") > # test your code > .C("tranptest", c("file1", "file2"), as.double(1,2,3,4)) > > Cheers, > Simon > > > > > > Alex > > --- On Mon, 3/8/10, Romain Francois > wrote: > > > >> From: Romain Francois > >> Subject: Re: [Rd] for help on building a R package > with several R function and a bunch of c, c++ > >> To: alex46...@yahoo.com > >> Cc: r-devel@r-project.org, > "Dirk Eddelbuettel" > >> Date: Monday, March 8, 2010, 2:47 AM > >> Hi, > >> > >> Yes, the problem is with spaces in path names. > This has > >> been fixed and > >> will appear as Rcpp 0.7.8 in a few days. > >> > >> If you are in a rush, you can build it from svn, > or quote > >>
Re: [Rd] for help on building a R package with several R function and a bunch of c, c++
Alex, On Mar 8, 2010, at 15:44 , alex46...@yahoo.com wrote: Yes! that is what I am looking for. When I post my question, I said I cannot catch the key point in "Writing R Extensions". Follow your suggestion, I almost have reached my goal although I passed the R CMD check mypackage. Before I install it (I need ask UNIX adminstrator to do it), I check the package, I got the information dyn.load("tranptest.so") filenames<-c("Mrklist.txt","CCdata.txt","outputfile") param<-c(1,0,1,0,1,1) .C("tranptest",as.character(filenames),as.double(param)) *** caught segfault *** address 0, cause 'memory not mapped' Traceback: 1: .C("tranptest",as.character(filenames), as.double(param)) Do you have any clue about the error? I think it is very close tothe end. I don't see your C code so I can't tell -- use "R -d gdb" to run R in a debugger so you can look at the exact spot of the crash. Is it possible that you get thrown off by the 0-based indexing in C and opposed to 1-based indexing in R? in extern "C" void tranptest(char **fn, double *par) { you want to access the values as fn[0], fn[1], fn[2] and par[0], par[1], par[2], .. etc. Cheers, Simon Thank you so much . You save me a tons of time, Alex --- On Mon, 3/8/10, Simon Urbanek wrote: From: Simon Urbanek Subject: Re: [Rd] for help on building a R package with several R function and a bunch of c, c++ To: alex46...@yahoo.com Cc: "Romain Francois" , r-devel@r-project.org , "Dirk Eddelbuettel" Date: Monday, March 8, 2010, 12:53 PM Alex, On Mar 8, 2010, at 12:16 , alex46...@yahoo.com wrote: I built R package with only R code before, this is first time I build R package with mixed R code and C, C++ code. I would try Rcpp on our center UNIX, before I ask the administrator to install it, I need confirm several issue are right. Thank you for you patient. 1, I change main function as a general function with certain name such as void tranptest(char* filename[], double* para[]), and copy this file and other related c, c++ h, program to /src, and removed makefile. Yes, that's perfect - for the kind of usage you don't need Rcpp at all - R supports C++ sources out of the box. Just make sure your tranptest function is either in a .c file or you put extern "C" in front of it if it's in .cpp , e.g: foo.cpp: extern "C" void tranptest(char **fn, double *par) { ... } 2, I noticed there is Makevars after I ran Rcpp.package.skeleton, do I need modify this file before I run R CMD build? what I need do for rcpp_hello_world.cpp rcpp_hello_world.cpp? it is template file handled by the program or it is for me to edit it as template? 3, Do I need write a R function such as tranptest<-function(inputfile, ctlfile,outfile, param1,param2,param3) { filenames<-c(inputfile,ctlfile,outfile) params<-as.vector(c(param1, param2,param3)) .C("tranptest", as.character(filenames),as.double(params)) } before I run R CMD build? if so, that means I put this R function in /R? yes, in R/foo.R (replace "foo" by any name you want) 4, Do I need do anything to run library.dyname to load those complied objects? If you have a namespace just add useDynLib(foo) where "foo" is the name of your package. If you don't have a namespace (or don't kwno what that is ;)) just add a file R/zzz.R with the following content to your package: .First.lib <- function(libname, pkgname) library.dynam("foo", pkgname, libname) where "foo" is the name of your package. Where I can make sure it successful and I can use .C("tranptest",) in R before the wholepackage installed? It's really simple - you don't need to install the package to test it. Assuming "foo" is the name of your package: Build the sources: R CMD SHLIB -o foo.so *.c* start R in the same directory: R # load the library you just compiled dyn.load("foo.so") # test your code .C("tranptest", c("file1", "file2"), as.double(1,2,3,4)) Cheers, Simon Alex --- On Mon, 3/8/10, Romain Francois wrote: From: Romain Francois Subject: Re: [Rd] for help on building a R package with several R function and a bunch of c, c++ To: alex46...@yahoo.com Cc: r-devel@r-project.org, "Dirk Eddelbuettel" Date: Monday, March 8, 2010, 2:47 AM Hi, Yes, the problem is with spaces in path names. This has been fixed and will appear as Rcpp 0.7.8 in a few days. If you are in a rush, you can build it from svn, or quote the path that is returned from CxxFlags. Feel free to get back to us with more questions, although I'd encourage you to use the dedicated Rcpp-devel mailing list : https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel Romain On 03/08/2010
Re: [Rd] for help on building a R package with several R function and a bunch of c, c++
I fixed the problem, it is related to my C++ code when I change main function to gneral function. You gave a great help! Thank you! Simon. have a good night! Alex __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel