Re: [R] Pass String from R to C
I tried using char ** but it is printing some random string. On Sat, Apr 23, 2011 at 6:08 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 11-04-23 7:04 PM, Jaimin Dave wrote: Hi, I am using a function which accepts the string from R and prints it. But when I am calling .C(main,hello); it is printing any random thing. My C function is void main(char *str) See Writing R Extensions. The declaration should be char **str. Duncan Murdoch { Rprintf(%s,str); } Can you help how to achieve this using .C interface? Thanks Jaimin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] Pass String from R to C
On 25/04/2011 12:51 PM, Jaimin Dave wrote: I tried using char ** but it is printing some random string. str is a pointer to an array of pointers to strings. That's what char** means. So you need to declare it that way, and use it that way. This works for me: File test.c: void test(char **str) { Rprintf(%s,*str); } Duncan Murdoch On Sat, Apr 23, 2011 at 6:08 PM, Duncan Murdochmurdoch.dun...@gmail.comwrote: On 11-04-23 7:04 PM, Jaimin Dave wrote: Hi, I am using a function which accepts the string from R and prints it. But when I am calling .C(main,hello); it is printing any random thing. My C function is void main(char *str) See Writing R Extensions. The declaration should be char **str. Duncan Murdoch { Rprintf(%s,str); } Can you help how to achieve this using .C interface? Thanks Jaimin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. __ R-help@r-project.org mailing list 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.
Re: [R] Pass String from R to C
On 25/04/2011 1:03 PM, Duncan Murdoch wrote: On 25/04/2011 12:51 PM, Jaimin Dave wrote: I tried using char ** but it is printing some random string. str is a pointer to an array of pointers to strings. That's what char** means. So you need to declare it that way, and use it that way. This works for me: File test.c: void test(char **str) { Rprintf(%s,*str); } Oops, I just noticed that the include was missing. The full file should have #include R.h at the beginning. Duncan Murdoch Duncan Murdoch On Sat, Apr 23, 2011 at 6:08 PM, Duncan Murdochmurdoch.dun...@gmail.comwrote: On 11-04-23 7:04 PM, Jaimin Dave wrote: Hi, I am using a function which accepts the string from R and prints it. But when I am calling .C(main,hello); it is printing any random thing. My C function is void main(char *str) See Writing R Extensions. The declaration should be char **str. Duncan Murdoch { Rprintf(%s,str); } Can you help how to achieve this using .C interface? Thanks Jaimin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. __ R-help@r-project.org mailing list 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.
[R] Pass String from R to C
Hi, I am using a function which accepts the string from R and prints it. But when I am calling .C(main,hello); it is printing any random thing. My C function is void main(char *str) { Rprintf(%s,str); } Can you help how to achieve this using .C interface? Thanks Jaimin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] Pass String from R to C
On 11-04-23 7:04 PM, Jaimin Dave wrote: Hi, I am using a function which accepts the string from R and prints it. But when I am calling .C(main,hello); it is printing any random thing. My C function is void main(char *str) See Writing R Extensions. The declaration should be char **str. Duncan Murdoch { Rprintf(%s,str); } Can you help how to achieve this using .C interface? Thanks Jaimin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. __ R-help@r-project.org mailing list 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.