Vladimir Eremeev
2007-May-25 07:33 UTC
[Rd] Problem with accessing internal variable in package.
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.
Vladimir Eremeev
2007-May-25 08:06 UTC
[Rd] Problem with accessing internal variable in package.
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.