[R] gfortran Makefile for cygwin
Hi all, I'm porting a package that I've worked on for OS X to Cygwin/Windows. This package requires a Makefile. My question is, how can I find out (or what is), the link command? Here is the OS X Makefile: RLIB_LOC=${R_HOME} F90_FILES=\ class_data_frame.f90 \ class_old_dbest.f90 \ class_cm_data.f90 \ class_cm.f90 \ class_bgw.f90 \ class_cm_mle.f90 \ cme.f90 FORTRAN_FILES=\ dgletc.f \ dglfgb.f\ dglfg.f\ dmdc.f\ mecdf.f %.o: %.f90 gfortran -c -g $ %.o: %.f gfortran -c -g $ bpkg.so: $(F90_FILES:%.f90=%.o) $(FORTRAN_FILES:%.f=%.o) gcc -Wall -bundle -flat_namespace -undefined suppress -L/sw/lib -L/usr/local/lib -o $@ $^ \ -L$(RLIB_LOC)/lib -lR ###EOF The -L lib dirs are not correct. On a *nix platform I would do something like this sh -x R CMD SHLIB ... to get at the R internal link information but I can't get that to work on Cygwin. Regards, Joel -- Joel Bremson Graduate Student Institute for Transportation Studies - UC Davis http://etrans.blogspot.com [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] S3 class question
Hi, I have a class called spss containing prepared info from an SPSS file. ... class(ret) = spss return(ret) The function that returns this defined in a file that I source into R. Also in that file is a function matSummary.spss. I think I ought to be able to call matSummary(ret) to run the function, but only matSummary.spss(ret) will work. What am I doing wrong here? This seems like a simple problem yet I've been able to find nothing in the archives about this. Joel -- Joel Bremson Graduate Student Institute for Transportation Studies - UC Davis http://etrans.blogspot.com [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] spss.read factor reversal
Hi, I'm having a problem with spss.read reversing my factor input. Here is the input copied from the spss data editor: color cost 1 2.30 2 2.40 3 3.00 1 2.10 1 1.00 1 2.00 2 4.00 2 3.20 2 2.33 3 2.44 3 2.55 For color, red=1, blue=2, and green = 3. It's type is 'String' and out=read.spss(file) out $COLOR [1] green blue red green green green blue blue blue red red Levels: red blue green $COST [1] 2.30 2.40 3.00 2.10 1.00 2.00 4.00 3.20 2.33 2.44 2.55 attr(,label.table) attr(,label.table)$COLOR green blue red 3 2 1 attr(,label.table)$COST NULL attr(,variable.labels) COLOR COST color cost =EOF=== Notice that the $COLOR factor data are inverted, looking at the integer output we see: as.integer(out$COLOR) [1] 3 2 1 3 3 3 2 2 2 1 1 The spss original data looks like this: 1 2 3 1 1 1 2 2 2 3 3 I can easily invert the output mathematically with: q = sapply(m,function(x){ x + 2*(median(unique(m))-x)}) (m is composed of sequential integers starting at one) ,but it seems as though something wrong is happening with read.spss. Any ideas? Joel Bremson Graduate Student UC Davis [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] mac osx, g95 package port problem
Hi all, I have a working package for linux, including fortran 95 code compiled with g95, that I need to port to OS X. The package works on Linux and seems to load on the Mac, but when I try to run a function that calls C or Fortran I'm told that the symbol is not loaded. I'm developing via a shell account on an OS X system, I don't have access to a desktop. The set up is: R 2.1.0 Patched (2005-05-12). Darwin Kernel Version 8.1.0 G95 (GCC 4.0.0 20050124 (experimental) (g95!) 06/20/05) Here is the Makefile: F90_FILES=\ dbest_dbase_class.f90 \ ... r_estimate.f90 \ FORTRAN_FILES=\ dgletc.f \ ... mecdf.f C_FILES=init.c CFLAGS=-g -fPIC %.o: %.f90 g95 -c -g $ %.o: %.f g95 -c -g $ %.o: %.c gcc -c -g $ bpkg.so: $(F90_FILES:%.f90=%.o) $(C_FILES:%.c=%.o) $(FORTRAN_FILES:%.f=%.o) g95 -L/Library/Frameworks -o $@ $^ -L/Library/Frameworks/R.framewo\ rk/Resources -end makefile Here is the relevant output of R CMD CHECK: * checking for working latex ...sh: line 1: latex: command not found NO * using log directory '/Users/jbremson/dev/bpkg.Rcheck' * using R version 2.1.0, 2005-05-12 * checking for file 'bpkg/DESCRIPTION' ... OK * this is package 'bpkg' version '1.0-1' * checking if this is a source package ... OK * Installing *source* package 'bpkg' ... ** libs g95 -c -g dbest_dbase_class.f90 g95 -c -g cm_class.f90 ... gcc -c -g init.c init.c: In function 'R_g95_init': init.c:22: warning: incompatible implicit declaration of built-in function 'strdup' g95 -c -g dgletc.f g95 -c -g dglfgb.f g95 -c -g dglfg.f g95 -c -g dglfgb.f g95 -c -g dglfg.f g95 -c -g dmdc.f g95 -c -g mecdf.f g95 -shared -L/Library/Frameworks -o bpkg.so dbest_dbase_class.o cm_class.o bgw_cla\ ss.o cm_mle_class.o pcm_dglg_o1.o cm_main.o r_estimate.o init.o dgletc.o dglfgb.o dg\ lfg.o dmdc.o mecdf.o -L/Library/Frameworks/R.framework/Resources g95: unrecognized option '-shared' ** R ** data ** help Building/Updating help pages for package 'bpkg' Formats: text html latex example estimate.model text html latex example ** building package indices ... * DONE (bpkg) * checking package directory ... OK * checking for portable file names ... OK * checking for sufficient/correct file permissions ... OK * checking DESCRIPTION meta-information ... OK * checking package dependencies ... OK * checking index information ... WARNING Empty file 'INDEX'. See the information on INDEX files and package subdirectories in section 'Creating R packages' of the 'Writing R Extensions' manual. * checking package subdirectories ... OK * checking R files for syntax errors ... OK * checking R files for library.dynam ... OK * checking S3 generic/method consistency ... WARNING Error: package/namespace load failed for 'bpkg' Call sequence: 2: stop(gettextf(package/namespace load failed for '%s', libraryPkgName(package)),\ call. = FALSE, domain = NA) 1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE) Execution halted See section 'Generic functions and methods' of the 'Writing R Extensions' manual. See section 'Generic functions and methods' of the 'Writing R Extensions' manual. * checking replacement functions ... WARNING Error: package/namespace load failed for 'bpkg' Call sequence: 2: stop(gettextf(package/namespace load failed for '%s', libraryPkgName(package)),\ call. = FALSE, domain = NA) 1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE) Execution halted In R, the argument of a replacement function which corresponds to the right hand side must be named 'value'. * checking foreign function calls ... WARNING Error: package/namespace load failed for 'bpkg' Call sequence: 2: stop(gettextf(package/namespace load failed for '%s', libraryPkgName(package)),\ call. = FALSE, domain = NA) 1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE) Execution halted See section 'System and foreign language interfaces' of the 'Writing R Extensions' manual. * checking Rd files ... OK * checking for missing documentation entries ... ERROR Error: package/namespace load failed for 'bpkg' -EOF Obviously, there is a package/namespace load filed. I looked at the mentioned R documentation and didn't find anything I thought relevant. Here is the NAMESPACE file for good measure. The package is called bpkg. --- useDynLib(bpkg) export(dummy,estimate.model,em2) -EOF--- I have checked the bpkg.so file with nm and the symbols for all functions are present. How can I get R to see the symbols for the package? Regards, Joel Bremson Graduate Student UC Davis [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] segmentation fault - debugging
Hi all, I'm trying to debug some fortran 95 code that I'm bringing in with a dyn.load(). I'm compiling a number of files using g95 on intel linux w/ R 2.1.0. The .so file loads without complaint, but when I try to call it I get a seg fault. I was hoping I could get a core dump in order to get some more clues about what is going on, but no luck. I'm relatively new to fortran programming and have never used gdb before, although I'm familiar with other debuggers. Any tips on how to proceed from this point would be appreciated. Regards, Joel Bremson Statistics Graduate Student UC Davis [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] using src/Makevars file
Hi all, Thanks to all who offered advice on using F95 in R. Now I'm trying to compile a test package using gfortran, Linux 2.4.21 and R 2.1.0. I was able to successfully compile and use a test F95 routine by setting my environment variables as follows in bash: export PATH=~/bin/:$PATH export F77=gfortran export LD_LIBRARY_PATH=~/bin/irun/lib export GFORTRAN_STDIN_UNIT=-1 Now I'm trying to write a Makevars file for my test package and not quite sure how to do it. I've tried FF=gfortran GFORTRAN_STDIN_UNIT=-1 FLIBS=/home/jbremson/bin/irun/lib/libgfortran.a but when running an R CMD check on the package I see that it's still using g77 to compile: -output ... ** libs g77 -fPIC -g -O2 -c estimate.f -o estimate.o estimate.f: In subroutine `estimate': estimate.f:20: forall (i = 1:nxrows) beta(i) = i * 2 ^ Invalid declaration of or reference to symbol `forall' at (^) [initially seen at (^)] ... end output The code compiles using: gfortran -c estimate.f I can run my code if I build the .so by hand and then dyn.load it. Here is my F95 test code: subroutine estimate(beta, yij, nij, nxrows, nxcols,xmat, irequest, ierror) integer nxrows, nxcols, yij, nij, irequest, ierror double precision beta(nxrows), xmat(nxrows,nxcols) integer i i = 0 c fortran 95 version forall (i = 1:nxrows) beta(i) = i * 2 ierror = 0 end Regards, Joel Bremson UC Davis [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Fortran 95 in R ?
Is it possible to run Fortran 95 code from R? I don't think so, but hopefully someone can prove me wrong. Here is the test I tried: A little fortran 95 subroutine: subroutine allloc() real, dimension(:, :), allocatable :: a integer :: n n = 10 allocate(a(n,n+1)) end I then compiled: g95 -c allloc.f R CMD SHLIB allloc.o Here is what happens when I try to dyn.load it in R 2.1.0 dyn.load(allloc.so) Error in dyn.load(x, as.logical(local), as.logical(now)) : unable to load shared library '/home/jbremson/dev/f_code/allloc.so': /home/jbremson/dev/f_code/allloc.so: undefined symbol: _g95_filename Is there any way to deal with this? Is it somehow possible to reach the fortran 95 through C and avoid this whole problem? Regards, Joel Bremson UC Davis [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] simple addition in R, now fast easy!
At last, simple addition in R is now fast and easy!!! They said it could never be done, but they've never heard of Fortran. In order to add two numbers in R before you had to type: 7 + 3 It was tedious to type and several hours could pass as you waited for your return value. So, imagine the excitement around your lab or office when you type in: .Fortran(add,as.numeric(7),as.numeric(3),as.numeric(0)) and get your result back faster then a greased goat! Well now you can! Here's how: First create a file called add.f with the following code: -clip c Add two numbers subroutine add(a,b,c) double precision a,b,c c = a + b end --end clip-- Don't disturb the spacing, Fortran is fussy about that. Now compile you're code: g77 -c add.f Now make a shared lib for R (unix/linux): R CMD SHLIB add.o This will create a file called 'add.so' Now go into R: dyn.load(add.so) # you might need an explicit path here And now you too have the power of fast, easy, simple addition!! .Fortran(add,as.numeric(7),as.numeric(3),as.numeric(0)) If you want to get real fancy you can put your .Fortran call into a function: myadd = function(a,b){ out = .Fortran(add,as.numeric(a),as.numeric(b),c=as.numeric(0)) return(out$c) } x = myadd(3,7) [1] 10 And you've done it! Be vanquished naysayers, simple addition will trouble us no more! (I thought a very simple tutorial on integrating Fortran code into R might be of use.) Joel Bremson [EMAIL PROTECTED] Statistics Graduate Student UC Davis [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] 3d scatter plot with drop line
This is a follow up to my question from yesterday. I want to do in R what is called a 3d scatter plot with drop lines in S-PLUS. Basically, it's a 3dscatterplot with lines connecting the x-y grid to the z points. The lines give a better perspective on the shape of the data surface. How to? Joel Bremson UC Davis Statistics __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] persp grid
I've got a 4x4 matrix of points from a 2-way ANOVA I'd like to plot. The x,y correspond to the treatment groups and look like this ((1,1),(1,2),(1,3),(1,4),(2,1),...). The z is the 4x4 matrix. How can I get persp to grid the x,y axis with only the numbers 1-4 on both? Regards, Joel Bremson UC Davis Statistics Dept. __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] why should you set the mode in a vector?
Hi all, If I write v = vector(mode=numeric,length=10) I'm still allowed to assign non-numerics to v. Furthermore, R figures out what kind of vector I've got anyway when I use the mode() function. So what is it that assigning a mode does? Joel __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html