Re: [Rd] How to test if R is running on a Mac

2007-09-19 Thread Vladimir Eremeev


Gregor Gorjanc-2 wrote:
 
 Hi!
 
 Is there any way to test if R is running on a Mac? I usually use
 value of .Platform$OS.type for windows or unix, but Mac falls in the
 latter group.
 
 Thanks, Gregor
 

What is in .Platform$path.sep?
Windows has ;, unix has :.
Mac?
-- 
View this message in context: 
http://www.nabble.com/How-to-test-if-R-is-running-on-a-Mac-tf4481121.html#a12778663
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] How to test if R is running on a Mac

2007-09-19 Thread Vladimir Eremeev



Vladimir Eremeev wrote:
 
 
 Gregor Gorjanc-2 wrote:
 
 Hi!
 
 Is there any way to test if R is running on a Mac? I usually use
 value of .Platform$OS.type for windows or unix, but Mac falls in the
 latter group.
 
 Thanks, Gregor
 
 
 What is in .Platform$path.sep?
 Windows has ;, unix has :.
 Mac?
 
And what is in .Platform$file.sep?
-- 
View this message in context: 
http://www.nabble.com/How-to-test-if-R-is-running-on-a-Mac-tf4481121.html#a12778683
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] How to correctly write a package?

2007-05-28 Thread Vladimir Eremeev

I am writing a package.

Please, study the sequence of my actions below, and comment, what's
incorrect.
The package contains pure R code.

1. At the one level up from the package directory, from the system command
prompt:
R CMD build --binary ac9

This produces the file ac9_0.1.zip (The package name is ac9, and the
package's DESCRIPTION file says its version is 0.1)

2. Then I run Rgui in the other directory and Install package(s) from local
zip files

3. Issue the following commands in the command of Rgui from step 2 :

library(ac9)
 [calls to functions from the package] 

4. If I see errors, I quit Rgui from step 2, then change (hopefully)
properly the source package code, and
go to step 1.

What would happen if I don't quit Rgui from the step 2?
Would it reload the new function definitions?

Is there any other methods to refine a packaged code, which experienced
package writers use in their routine work?

I have created package source using package.skeleton, and have documented
the functions. 
Updating of the function body and re-use of the package.skeleton with
force=TRUE overwrites the documentation files. This disallows often use of
this function, or requires keeping the backup copy of the package sources.
-- 
View this message in context: 
http://www.nabble.com/How-to-correctly-write-a-package--tf3828586.html#a10837938
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Problem with accessing internal variable in package.

2007-05-25 Thread Vladimir Eremeev

I am writing a package, which contains several functions and variables. 
The variables are for internal use by functions. 
Functions are ment to be callable by a user.
However, the function cannot access these variables.

The package contains only R code, and was created using package.skeleton

package.skeleton(name=ac9,
 list=c(ls(pattern=(AB2)|(ac9)),
Chl,Pro,LP,SP,syn,unk,Y,Nh,
plot.C,read.AC9.data,EstimC,plot.AC9),
  namespace=TRUE,force=TRUE)

Among others, the package contains the functions EstimC, AB2C, AB2C.S, and
AB2C.HK, and variables ac9nw, ac9wl, ac9aw, ...
Functions use these variables for calculations, and I would like to hide
them from users.

The file NAMESPACE contains the single line:
  export(AB2C.HK,AB2C,AB2C.S,EstimC,plot.C,read.AC9.data,plot.AC9)

I am getting the following error:
Error in AB2C(a, b, model.type) : object ac9nw not found

 traceback()
2: AB2C(a, b, model.type)
1: EstimC(i, plot.base.name = paste(plt.base.name, S_, sep = ), 
   model.type = S)

 sessionInfo()
R version 2.5.0 Patched (2007-05-13 r41549) 
i386-pc-mingw32 

locale:
LC_COLLATE=Russian_Russia.1251;LC_CTYPE=Russian_Russia.1251;LC_MONETARY=Russian_Russia.1251;LC_NUMERIC=C;LC_TIME=Russian_Russia.1251

attached base packages:
[1] datasets  utils stats graphics  grDevices methods  
[7] base 

other attached packages:
 ac9 xlsReadWrite   matlab MASS 
   0.1  1.3.2  0.8-1 7.2-33 


-- 
View this message in context: 
http://www.nabble.com/Problem-with-accessing-internal-variable-in-package.-tf3814649.html#a10798364
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Problem with accessing internal variable in package.

2007-05-25 Thread Vladimir Eremeev

This is my first package, and clearly, I'm missing something.

After reading again manuals about name spaces and hooks, I have defined the
function .onLoad,
which implicitly assigns all internal variables with -
Then I have deleted previous package directory and changed the call to
package.skeleton

package.skeleton(name=ac9,
 list=c(ls(pattern=(AB2)),
   
plot.C,read.AC9.data,EstimC,plot.AC9,.onLoad),
  namespace=TRUE,force=TRUE)

It has created file ac9/R/ac9-internal.R, containing the function .onLoad,
however, its body completely differs from that I have defined before.



Vladimir Eremeev wrote:
 
 I am writing a package, which contains several functions and variables. 
 The variables are for internal use by functions. 
 Functions are ment to be callable by a user.
 However, the function cannot access these variables.
 
 The package contains only R code, and was created using package.skeleton
 
 package.skeleton(name=ac9,
  list=c(ls(pattern=(AB2)|(ac9)),
 Chl,Pro,LP,SP,syn,unk,Y,Nh,
 plot.C,read.AC9.data,EstimC,plot.AC9),
   namespace=TRUE,force=TRUE)
 
 Among others, the package contains the functions EstimC, AB2C, AB2C.S, and
 AB2C.HK, and variables ac9nw, ac9wl, ac9aw, ...
 Functions use these variables for calculations, and I would like to hide
 them from users.
 
 The file NAMESPACE contains the single line:
   export(AB2C.HK,AB2C,AB2C.S,EstimC,plot.C,read.AC9.data,plot.AC9)
 
 I am getting the following error:
 Error in AB2C(a, b, model.type) : object ac9nw not found
 
 traceback()
 2: AB2C(a, b, model.type)
 1: EstimC(i, plot.base.name = paste(plt.base.name, S_, sep = ), 
model.type = S)
 
 sessionInfo()
 R version 2.5.0 Patched (2007-05-13 r41549) 
 i386-pc-mingw32 
 
 locale:
 LC_COLLATE=Russian_Russia.1251;LC_CTYPE=Russian_Russia.1251;LC_MONETARY=Russian_Russia.1251;LC_NUMERIC=C;LC_TIME=Russian_Russia.1251
 
 attached base packages:
 [1] datasets  utils stats graphics  grDevices methods  
 [7] base 
 
 other attached packages:
  ac9 xlsReadWrite   matlab MASS 
0.1  1.3.2  0.8-1 7.2-33 
 

-- 
View this message in context: 
http://www.nabble.com/Problem-with-accessing-internal-variable-in-package.-tf3814649.html#a10798787
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] private variables in package.

2007-05-25 Thread Vladimir Eremeev

I am sorry, my previous questions about hiding variables from users in a
package were obscure and vague, and would like to clarify them.

This should be a basic question.
I am writing my first package.
It has several functions, which should be callable by users.
These functions use several variables, and I would like to hide these
variables from users.
How can I do it?

For example, the package has a function AB2C, which uses the variable ac9nw.
If I add the file NAMESPACE, exporting only AB2C, then I get the error:
  
   Error in AB2C(a, b, model.type) : object ac9nw not found

I also tried to include in the .onLoad function the code, defining these
variables with -
However, this code has created all internal variables in the global
environment.


-- 
View this message in context: 
http://www.nabble.com/private-variables-in-package.-tf3815306.html#a10800416
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] private variables in package.

2007-05-25 Thread Vladimir Eremeev

Thank you for the answer.

Here is everything.

ac9wl-c(412,440,488,510,532,555,650,676,715)
ac9nw-length(ac9wl)

AB2C -function(a,b,model.type=S) {  
  nza-dim(a)[1]
  nwa-dim(a)[2]
  nzb-dim(b)[1]
  nwb-dim(b)[2]

  if(nza!=nzb || nwa!=ac9nw || nwb!=ac9nw) {
warning('AB2C: Dimensions of the input matrices are invalid')
return(NULL);
  }

 [ further calculations, they  do not use ac9nw ]  
}



ripley-3 wrote:
 
 R has debugging features: see 'Writing R Extensions'.  Please make use of 
 them, e.g. options(error=recover) will enable you to explore the 
 environments that are visible.
 
 We can only guess at this, not having function AB2C.
 
 On Fri, 25 May 2007, Vladimir Eremeev wrote:
 
 
 I am sorry, my previous questions about hiding variables from users in a
 package were obscure and vague, and would like to clarify them.

 This should be a basic question.
 I am writing my first package.
 It has several functions, which should be callable by users.
 These functions use several variables, and I would like to hide these
 variables from users.
 How can I do it?

 For example, the package has a function AB2C, which uses the variable
 ac9nw.
 If I add the file NAMESPACE, exporting only AB2C, then I get the error:

   Error in AB2C(a, b, model.type) : object ac9nw not found
 

-- 
View this message in context: 
http://www.nabble.com/private-variables-in-package.-tf3815306.html#a10801165
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] private variables in package.

2007-05-25 Thread Vladimir Eremeev

I do use this function.
Here is the example session, run from the newly created directory, without
.Rdata and .Rhistory files.

=== begin
R version 2.5.0 Patched (2007-05-13 r41549)
Copyright (C) 2007 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

 library(ac9)
 AB2C(matrix(rnorm(90),ncol=9),matrix(rnorm(90),ncol=9))
Error in AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9)) : 
object ac9nw not found
 options(error=recover)
 AB2C(matrix(rnorm(90),ncol=9),matrix(rnorm(90),ncol=9))
Error in AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9)) : 
object ac9nw not found

Enter a frame number, or 0 to exit   

1: AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))

Selection: 1
Called from: eval(expr, envir, enclos)
Browse[1] ls()
[1] a  b  model.type nwanwb   
[6] nzanzb   
Browse[1] search()
 [1] .GlobalEnvpackage:ac9   package:stats
 [4] package:graphics  package:grDevices package:utils
 [7] package:datasets  package:methods   Autoloads
[10] package:base 
Browse[1] n

Enter a frame number, or 0 to exit   

1: AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))

Selection: 1
Browse[1] n

Enter a frame number, or 0 to exit   

1: AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))
Selection: 0


=== Pause of the session, don't quit from R.

The function AB2C tries to work, if I use the data function.
But this data function makes the ac9nw visible in the global environment.

=== Continuing the sample session:

 data(ac9nw)
 ls()
[1] ac9nw
 ac9nw
[1] 9

 AB2C(matrix(rnorm(90),ncol=9),matrix(rnorm(90),ncol=9))
Error in eval(expr, envir, enclos) : object Pro not found

Enter a frame number, or 0 to exit   

 1: AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))
 2: NextMethod(AB2C)
 3: AB2C.S(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))
 4: lm(t(cbind(a, b)) ~ Pro + syn + unk + Y + Nh + 0, offset = c(ac9aw,
ac9bw))
 5: eval(mf, parent.frame())
 6: eval(expr, envir, enclos)
 7: model.frame(formula = t(cbind(a, b)) ~ Pro + syn + unk + Y + Nh + 0,
offset = c(ac9a
 8: model.frame.default(formula = t(cbind(a, b)) ~ Pro + syn + unk + Y + Nh
+ 0, offset 
 9: eval(predvars, data, env)
10: eval(expr, envir, enclos)

Selection: 0

The function AB2C now sees ac9nw, and gives similar errors, related to other
hidden variables.


Duncan Murdoch-2 wrote:
 
 On 5/25/2007 7:27 AM, Vladimir Eremeev wrote:
 Thank you for the answer.
 
 Here is everything.
 
 ac9wl-c(412,440,488,510,532,555,650,676,715)
 ac9nw-length(ac9wl)
 
 AB2C -function(a,b,model.type=S) {  
   nza-dim(a)[1]
   nwa-dim(a)[2]
   nzb-dim(b)[1]
   nwb-dim(b)[2]
 
   if(nza!=nzb || nwa!=ac9nw || nwb!=ac9nw) {
 warning('AB2C: Dimensions of the input matrices are invalid')
 return(NULL);
   }
 
  [ further calculations, they  do not use ac9nw ]  
 }
 
 
 That would work, so my guess is that you aren't using that function.  If 
 you have a function named AB2C in your global environment, R will find 
 it before this one, and it may not be able to see the ac9nw variable.
 
 Duncan Murdoch
 
 

-- 
View this message in context: 
http://www.nabble.com/private-variables-in-package.-tf3815306.html#a10801823
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] solved.

2007-05-25 Thread Vladimir Eremeev

By removing the data directory (which package.skeleton has created, and where
it has put all my variables in files with .rda extension) and adding one
more file to the R directory, containing the variable assignments.


Vladimir Eremeev wrote:
 
 I do use this function.
 Here is the example session, run from the newly created directory, without
 .Rdata and .Rhistory files.
 
 === begin
 R version 2.5.0 Patched (2007-05-13 r41549)
 Copyright (C) 2007 The R Foundation for Statistical Computing
 ISBN 3-900051-07-0
 
 R is free software and comes with ABSOLUTELY NO WARRANTY.
 You are welcome to redistribute it under certain conditions.
 Type 'license()' or 'licence()' for distribution details.
 
 R is a collaborative project with many contributors.
 Type 'contributors()' for more information and
 'citation()' on how to cite R or R packages in publications.
 
 Type 'demo()' for some demos, 'help()' for on-line help, or
 'help.start()' for an HTML browser interface to help.
 Type 'q()' to quit R.
 
 library(ac9)
 AB2C(matrix(rnorm(90),ncol=9),matrix(rnorm(90),ncol=9))
 Error in AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9)) : 
 object ac9nw not found
 options(error=recover)
 AB2C(matrix(rnorm(90),ncol=9),matrix(rnorm(90),ncol=9))
 Error in AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9)) : 
 object ac9nw not found
 
 Enter a frame number, or 0 to exit   
 
 1: AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))
 
 Selection: 1
 Called from: eval(expr, envir, enclos)
 Browse[1] ls()
 [1] a  b  model.type nwanwb   
 [6] nzanzb   
 Browse[1] search()
  [1] .GlobalEnvpackage:ac9   package:stats
  [4] package:graphics  package:grDevices package:utils
  [7] package:datasets  package:methods   Autoloads
 [10] package:base 
 Browse[1] n
 
 Enter a frame number, or 0 to exit   
 
 1: AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))
 
 Selection: 1
 Browse[1] n
 
 Enter a frame number, or 0 to exit   
 
 1: AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))
 Selection: 0
 
 
 === Pause of the session, don't quit from R.
 
 The function AB2C tries to work, if I use the data function.
 But this data function makes the ac9nw visible in the global environment.
 
 === Continuing the sample session:
 
 data(ac9nw)
 ls()
 [1] ac9nw
 ac9nw
 [1] 9
 
 AB2C(matrix(rnorm(90),ncol=9),matrix(rnorm(90),ncol=9))
 Error in eval(expr, envir, enclos) : object Pro not found
 
 Enter a frame number, or 0 to exit   
 
  1: AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))
  2: NextMethod(AB2C)
  3: AB2C.S(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))
  4: lm(t(cbind(a, b)) ~ Pro + syn + unk + Y + Nh + 0, offset = c(ac9aw,
 ac9bw))
  5: eval(mf, parent.frame())
  6: eval(expr, envir, enclos)
  7: model.frame(formula = t(cbind(a, b)) ~ Pro + syn + unk + Y + Nh + 0,
 offset = c(ac9a
  8: model.frame.default(formula = t(cbind(a, b)) ~ Pro + syn + unk + Y +
 Nh + 0, offset 
  9: eval(predvars, data, env)
 10: eval(expr, envir, enclos)
 
 Selection: 0
 
 The function AB2C now sees ac9nw, and gives similar errors, related to
 other hidden variables.
 
 
 Duncan Murdoch-2 wrote:
 
 On 5/25/2007 7:27 AM, Vladimir Eremeev wrote:
 Thank you for the answer.
 
 Here is everything.
 
 ac9wl-c(412,440,488,510,532,555,650,676,715)
 ac9nw-length(ac9wl)
 
 AB2C -function(a,b,model.type=S) {  
   nza-dim(a)[1]
   nwa-dim(a)[2]
   nzb-dim(b)[1]
   nwb-dim(b)[2]
 
   if(nza!=nzb || nwa!=ac9nw || nwb!=ac9nw) {
 warning('AB2C: Dimensions of the input matrices are invalid')
 return(NULL);
   }
 
  [ further calculations, they  do not use ac9nw ]  
 }
 
 
 That would work, so my guess is that you aren't using that function.  If 
 you have a function named AB2C in your global environment, R will find 
 it before this one, and it may not be able to see the ac9nw variable.
 
 Duncan Murdoch
 
 
 
 

-- 
View this message in context: 
http://www.nabble.com/private-variables-in-package.-tf3815306.html#a10802257
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] section needed in FAQ - Using R (PR#9698)

2007-05-21 Thread Vladimir Eremeev

There are also R reference cards and other quick- and kick-starting manuals,
mentioned in the documentation.


Ray Kiddy-2 wrote:
 
 There is no section in the FAQ equivalent to Using R. The R Basics is
 too
 basic. I would say it addresses meta-R questions, such as installing.
 
 I had a FAQ that I would think would be a basic Using R question,
 namely: How
 does one generate random numbers?. It is actually non-trivial to answer
 this if
 one is new to R, as there are too many hits for Random and they dive too
 deeply.
 
 My answer to this FAQ would be:
 
 In order to generate random numbers, there are r methods for every
 distribution. Distributions include Uniform (runif), Binomial (rbinom),
 Normal
 (rnorm), Cauchy (rcauchy), Chi Square (rchisq), Exponential (rexp), Gamma
 (rgamma), and many more.
 
 By the way, the R program itself is really badly in need of an
 appropos() to
 go alongside help(). Perhaps help() can be renamed to hunt() or
 huntAndPeck().
 

-- 
View this message in context: 
http://www.nabble.com/section-needed-in-FAQ---Using-R-%28PR-9698%29-tf3788564.html#a10717487
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] How to customize the list of exported functions in a shared library

2007-02-05 Thread Vladimir Eremeev

Dear R users,

I am writing binding from C library to R.
I use R 2.4.1, windows XP, and MinGW.

commands

set PKG_CPPFLAGS=-I../sources -I. 
set PKG_LIBS=-Lc:/mingw/lib -lfl -liberty
set DEBUG=T

R CMD SHLIB -d --output=Rsnns.dll  [ list of all C sources]

produce the DLL having all defined functions in the export list.
This doesn't satisfy me, as I would like to hide most of defined functions
and export only a couple of functions from the library and interface
functions which I have written in order to call them from R.

The ../sources directory contains also two compiled libraries, created with
ar. 
If I try to link my DLL with them,  that is

R CMD SHLIB -d --output Rsnns.dll Rsnns.c
-Wl,-Lc:/mingw/lib,-lfl,-L../sources,-lkernel,-lfunc

desired functions from the library are not exported, export list gets only
interface functions in the C file.

And GCC seems to ignore the .def file, which I create.

Thank you.
-- 
View this message in context: 
http://www.nabble.com/How-to-customize-the-list-of-exported-functions-in-a-shared-library-tf3173289.html#a8803194
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] How to customize the list of exported functions in a shared library

2007-02-05 Thread Vladimir Eremeev


Andrew Piskorski wrote:
 
 On Mon, Feb 05, 2007 at 01:28:24AM -0800, Vladimir Eremeev wrote:
 I am writing binding from C library to R.
 I use R 2.4.1, windows XP, and MinGW.
 
 R CMD SHLIB -d --output=Rsnns.dll  [ list of all C sources]
 
 R CMD SHLIB -d --output Rsnns.dll Rsnns.c
 -Wl,-Lc:/mingw/lib,-lfl,-L../sources,-lkernel,-lfunc
 
 You should probably also show us the actual compiler/linker commands
 that R CMD SHLIB is generating, so we can be sure of what's really
 going on.
 

It calls gcc:
gcc  -I../sources -I.  -IC:/PROGRA~1/R/include  -gdwarf-2 -Wall -O2
-std=gnu99   -c rsnns.c -o rsnns.o
gcc  -shared   -o Rsnns.dll Rsnns.def [ lots of *.o ]  -LC:/PROGRA~1/R/bin
-Lc:/mingw/lib -lfl -liberty   -lR

The file Rsnns.def is generated automatically and is deleted on success.
On error, it remains, and contains export of all symbols.
Probably GCC generates it, I haven't tracked its generation in the R's
scripts.


Andrew Piskorski wrote:
 
 I'm not sure what you may have to do differently with MinGW on Windows
 (what linker does that use anyway?), but for comparison, here's how I
 do it for R 2.2.1, on Linux (Ubuntu Dapper 6.06), with gcc 4.0.3, and
 Gnu ld 2.16.91:
 

gcc.EXE (GCC) 3.4.2 (mingw-special)
GNU ld version 2.15.91 20040904

Thank you, I'll study this linker option.


Andrew Piskorski wrote:
 
 For my own custom R package's C code, my Makefile says:
   OBJ = ../foo.o $(patsubst %.c,%.o,$(wildcard ../source/[a-z]*.c))
   $(OBJ): %.o:  %.c $(HDRS)
   R.so: $(OBJ) Makevars vis.map
   R CMD SHLIB -o my_pkg_name_R.so $(OBJ)
 
 My Makevars includes this:
 
   PKG_LIBS = -Wl,--version-script=vis.map
 
 And when I build my R package, the R.so make target above generates
 this link command:
 
   gcc -shared -o my_pkg_name_R.so [lots of *.o filenames here]
 -Wl,--version-script=vis.map -L/usr/lib/R/lib -lR
 
 My vis.map file, which uses Gnu ld syntax, looks like this:
 
   {
  global: my_pkg_*;
  local:*;
   };
 
 That works, my shared library exports ONLY the symbols starting with
 my_pkg_, everything else remains private.
 
 It's the --version-script linker option doing the magic.  Even with
 Gnu ld, there are definitely other ways to control symbol visibility,
 but that one seemed most convenient in my case.
 -- 
 Andrew Piskorski [EMAIL PROTECTED]
 http://www.piskorski.com/
 
 

-- 
View this message in context: 
http://www.nabble.com/How-to-customize-the-list-of-exported-functions-in-a-shared-library-tf3173289.html#a8807456
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] How to customize the list of exported functions in a shared library (update)

2007-02-05 Thread Vladimir Eremeev



Vladimir Eremeev wrote:
 
 
 It calls gcc:
 gcc  -I../sources -I.  -IC:/PROGRA~1/R/include  -gdwarf-2 -Wall -O2
 -std=gnu99   -c rsnns.c -o rsnns.o
 gcc  -shared   -o Rsnns.dll Rsnns.def [ lots of *.o ]  -LC:/PROGRA~1/R/bin
 -Lc:/mingw/lib -lfl -liberty   -lR
 
 The file Rsnns.def is generated automatically and is deleted on success.
 On error, it remains, and contains export of all symbols.
 Probably GCC generates it, I haven't tracked its generation in the R's
 scripts.
 

This file is generated in R scripts.
MkRules contains

%.dll:
@$(ECHO) EXPORTS  $*.def
@$(NM) $^ | $(SED) -n 's/^ [BCDRT] _/ /p'  $*.def
$(DLL) -shared $(DLLFLAGS) $($*-DLLFLAGS) -o $@ $*.def $^ $($*-DLLLIBS)
$(DLLLIBS)
@$(RM) $*.def

-- 
View this message in context: 
http://www.nabble.com/How-to-customize-the-list-of-exported-functions-in-a-shared-library-tf3173289.html#a8807621
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Rscript on Windows

2007-01-26 Thread Vladimir Eremeev

ActivePerl has '-x' switch which tells it to skip all lines in the file till
#!.
This allows writing perl scripts in ordinary .bat files.

?shQuote contains a link with the following perl script example:
===8===
@echo off
:: hello.bat
:: Windows executable Perl script
:: Note:
::   assumes perl.exe is in path
::   otherwise, use absolute path
perl -x -S %0 %*
goto end
#!perl

print Hello, World!\n;
__END__
:end
:: -- end of hello.bat --

Windows Notes: 
 -x  (lower case x): Skip all text until shebang line. 
 -S  (upper case S): Look for script using PATH variable. Special meaning
in Windows: appends .bat or .cmd if lookup for name fails and name does not
have either suffix. 
 %*  only on WinNT/2K/XP; use %1 %2 . . . %9 on Win9x/DOS 
===8===

I think the simplest way to implement shebang on windows would be embedding
one more command line switch with similar functionality to perl's '-x'.

-- 
View this message in context: 
http://www.nabble.com/Rscript-on-Windows-tf3120774.html#a8651815
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] I have won!

2007-01-25 Thread Vladimir Eremeev


Vladimir Eremeev wrote:
 
 That is, R correctly calls C wrapper, 
 ...
 its arguments have correct values
 
That was not the case. 
I forgot as.integer() in the .C call and one of the arguments was 0 instead
of 1.
Since that, indices in the array were calculated incorrectly, and the
program tried reading prohibited memory address.
-- 
View this message in context: 
http://www.nabble.com/how-to-trace-what-crashes-R-tf3083985.html#a8612674
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] is it necessary to always register C routines with R_registerRoutines?

2007-01-24 Thread Vladimir Eremeev

sorry, forgot to mention.

krui_getVersion returns char *

SEXP snns_getVersion(void)
{SEXP version;
 char *v;
  
  PROTECT(version=NEW_CHARACTER(15));
  v=CHARACTER_POINTER(version);
  strcpy(v,krui_getVersion());
  UNPROTECT(1);
  return version;
}


-- 
View this message in context: 
http://www.nabble.com/is-it-necessary-to-always-register-C-routines-with-R_registerRoutines--tf3063486.html#a8520292
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] is it necessary to always register C routines with R_registerRoutines?

2007-01-24 Thread Vladimir Eremeev

I am writing bindings to the neural network simulator SNNS.
At present I have used only .C interface, now I'm studying .Call interface.

I have adapted the example from page 77 of r-exts.pdf, however, it crashes
R.
I use MingW as recommended by Duncan Murdoch.
Please, tell me what I am missing.
The code is below.

Thank you.

SEXP snns_getVersion(void)
{SEXP version;
 char *v;
  
  PROTECT(version=NEW_CHARACTER(15));
  v=CHARACTER_POINTER(version);
  strcpy(v,krui_getVersion());
  UNPROTECT(1);
  return version;
}

 sessionInfo()
R version 2.4.1 (2006-12-18) 
i386-pc-mingw32 

locale:
LC_COLLATE=Russian_Russia.1251;LC_CTYPE=Russian_Russia.1251;LC_MONETARY=Russian_Russia.1251;LC_NUMERIC=C;LC_TIME=Russian_Russia.1251

attached base packages:
[1] stats graphics  grDevices utils datasets  methods  
[7] base 
 

-- 
View this message in context: 
http://www.nabble.com/is-it-necessary-to-always-register-C-routines-with-R_registerRoutines--tf3063486.html#a8519680
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] how to trace what crashes R

2007-01-24 Thread Vladimir Eremeev

I am writing bindings to the C library (neural network simulator SNNS).
DLL was produced with the command
R CMD SHLIB  [source with C-wrappers, callable from R with .C and all
sources from the snns kernel]
I used latest MinGW.

The problem is. R crashes with the segmentation violation.
Tracing with the insight and with simple Rprintf's gave me that crash occurs
on the call of the function deeply in the snns kernel. 
That is, R correctly calls C wrapper, it calls the kernel function from the
so called user interface part, it calls another C function from the
internals, and that one calls the third C function. 
And the segmentation fault occurs on the call of that function, it doesn't
do anything, its arguments have correct values, and it works in the other
situations, for example, when I run executables from the SNNS (either gui
version of the simulator, or batch interpreter).
Moreover, I don't think the reason in the incorrect arguments, since the
called function doesn't do anything. 
Rprintf in the very beginning of its body doesn't work (I traced it in
console mode of R).

How could I trace, what happens?
-- 
View this message in context: 
http://www.nabble.com/how-to-trace-what-crashes-R-tf3083985.html#a8570488
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel