I'm using .C() and .External() and have no problems sending integers, reals or strings from R to C. Nor do I have problems sending integers or reals back from C to R. But I'm pulling my hair out trying to set a string value in a C function and then sending it back from C to to R. I've searched the usual sources and tried various casts, macros and allocation schemes, but I'm failing miserably. Could someone please put me out of my misery and point me to a working example? Thanks, -- Fernando -- Fernando Pineda Associate Professor Dept. of Molecular Microbiology & Immunology Johns Hopkins Bloomberg School of Public Health Room E5146 615 N. Wolfe St., Baltimore, MD 21205-2179 fernando.pineda at jhu.edu 443-287-3673 (office) 410-955-0105 (fax) http://www.pinedalab.jhsph.edu
Hallo! There is a package called BioSeq1 at bioconductor. It Is using the .C interface and was doing a lot of string manipulation. Should have tons of examples. The simplest way to do it is. You my alloc fist the char in R. mychar<-paste(rep(" ",1000),collapse="") tmp<-.C( as.character(mychar) nchar(mychar) ) You can write into the char on the C side what you like. The char will be in tmp[[1]] Sincerely Eryk *********** REPLY SEPARATOR *********** On 6/2/2004 at 11:22 PM Fernando Pineda wrote:>I'm using .C() and .External() and have no problems sending integers, >reals or strings from R to C. Nor do I have problems sending integers >or reals back from C to R. But I'm pulling my hair out trying to set >a string value in a C function and then sending it back from C to to >R. I've searched the usual sources and tried various casts, macros >and allocation schemes, but I'm failing miserably. Could someone >please put me out of my misery and point me to a working example? > >Thanks, > >-- Fernando >-- >Fernando Pineda >Associate Professor >Dept. of Molecular Microbiology & Immunology >Johns Hopkins Bloomberg School of Public Health >Room E5146 >615 N. Wolfe St., Baltimore, MD 21205-2179 >fernando.pineda at jhu.edu >443-287-3673 (office) >410-955-0105 (fax) >http://www.pinedalab.jhsph.edu > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.htmlDipl. bio-chem. Eryk Witold Wolski @ MPI-Moleculare Genetic Ihnestrasse 63-73 14195 Berlin 'v' tel: 0049-30-83875219 / \ mail: wolski at molgen.mpg.de ---W-W---- http://www.molgen.mpg.de/~wolski
>>>>> "Fernando" == Fernando Pineda <fernando.pineda at jhu.edu> >>>>> on Wed, 2 Jun 2004 23:22:22 -0400 writes:Fernando> I'm using .C() and .External() and have no Fernando> problems sending integers, reals or strings from R Fernando> to C. Nor do I have problems sending integers or Fernando> reals back from C to R. But I'm pulling my hair Fernando> out trying to set a string value in a C function Fernando> and then sending it back from C to to R. I've Fernando> searched the usual sources and tried various Fernando> casts, macros and allocation schemes, but I'm Fernando> failing miserably. Could someone please put me out Fernando> of my misery and point me to a working example? You did read the section entitled "Interface functions `.C' and `.Fortran'" in the "Writing R Extensions" manual ? In particular,>> The following table gives the mapping between the modes of R vectors >> and the types of arguments to a C function or FORTRAN subroutine. >> >> R storage mode C type FORTRAN type >> `logical' `int *' `INTEGER' >> `integer' `int *' `INTEGER' >> `double' `double *' `DOUBLE PRECISION' >> `complex' `Rcomplex *' `DOUBLE COMPLEX' >> `character' `char **' `CHARACTER*255'?? One working example is the R function formatC() with the C code in <Rsource>/src/appl/strsignif.c Martin Maechler