Re: [R-pkg-devel] define an environment in .onLoad

2019-01-29 Thread Martin Morgan
A variant (not quite as good because parent = emptyenv() is not an argument) is

pkg_data <- local({ a = 1; b =2; environment() })

If information at load time is also important, one might add

.onLoad <- function(libname, pkgname) {
pkg_data[["last_update"]] <- Sys.time()
}

which is actually a fun test of one's understanding of R's assignment and 
symbol look-up rules.

Martin Morgan

On 1/29/19, 4:50 PM, "R-package-devel on behalf of Gábor Csárdi" 
 
wrote:

You don't need .onLoad for this, just put the environment into the
package environment. E.g. simply add

pkg_data <- new.env(parent = emptyenv())

to your package code. Then you can refer to pkg_data from the
functions in the package.

Best,
Gabor

On Tue, Jan 29, 2019 at 9:40 PM Pascal Title  wrote:
>
> Hi,
>
> I am developing an R package where I would like to have a set of names
> defined once, and which could then be queried from within the various
> functions of the package. The way I have currently set this up is to 
define
> a new environment that contains these names.
>
> So, what I currently have is:
>
> .var <- new.env()
>
> .var$bio <- "bio_"
>
> .var$tmin <- "tmin_"
>
> .var$tmax <- "tmax_"
>
> What I would like is that this environment be created when the R package 
is
> loaded. That way, default values are automatically in place, and if the
> user would like to change the naming that they use for tmin, for example,
> they would just need to do (for example):
>
>
> .var$tmin <- ‘minTemp_'
>
>
> And then these names can be accessed from within any of the functions, and
> this is unlikely to conflict with any R objects the user is defining.
>
>
> Where I am stuck is how/where to define this new environment such that it
> is made available when the package is loaded. I tried including the
> following in R/zzz.R:
>
>
> .onLoad <- function(libname, pkgname) {
>
>
>   # define a custom environment for defining the naming of variables
>
> .var <- new.env()
>
> # default
>
> .var$bio <- "bio_"
>
> .var$tmin <- "tmin_"
>
> .var$tmax <- "tmax_"
>
> invisible()
>
> }
>
>
> But if I build/install the package, the .var environment is not already
> created. Any suggestions?
>
>
> Thanks!
>
> -Pascal
>
> [[alternative HTML version deleted]]
>
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel

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

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


Re: [R-pkg-devel] define an environment in .onLoad

2019-01-29 Thread Pascal Title
Thank you!
I had actually tried that, but forgot to export that additional R script.
This makes sense.


On January 29, 2019 at 16:47:20, Gábor Csárdi (csardi.ga...@gmail.com)
wrote:

You don't need .onLoad for this, just put the environment into the
package environment. E.g. simply add

pkg_data <- new.env(parent = emptyenv())

to your package code. Then you can refer to pkg_data from the
functions in the package.

Best,
Gabor

On Tue, Jan 29, 2019 at 9:40 PM Pascal Title  wrote:
>
> Hi,
>
> I am developing an R package where I would like to have a set of names
> defined once, and which could then be queried from within the various
> functions of the package. The way I have currently set this up is to
define
> a new environment that contains these names.
>
> So, what I currently have is:
>
> .var <- new.env()
>
> .var$bio <- "bio_"
>
> .var$tmin <- "tmin_"
>
> .var$tmax <- "tmax_"
>
> What I would like is that this environment be created when the R package
is
> loaded. That way, default values are automatically in place, and if the
> user would like to change the naming that they use for tmin, for example,
> they would just need to do (for example):
>
>
> .var$tmin <- ‘minTemp_'
>
>
> And then these names can be accessed from within any of the functions,
and
> this is unlikely to conflict with any R objects the user is defining.
>
>
> Where I am stuck is how/where to define this new environment such that it
> is made available when the package is loaded. I tried including the
> following in R/zzz.R:
>
>
> .onLoad <- function(libname, pkgname) {
>
>
> # define a custom environment for defining the naming of variables
>
> .var <- new.env()
>
> # default
>
> .var$bio <- "bio_"
>
> .var$tmin <- "tmin_"
>
> .var$tmax <- "tmax_"
>
> invisible()
>
> }
>
>
> But if I build/install the package, the .var environment is not already
> created. Any suggestions?
>
>
> Thanks!
>
> -Pascal
>
> [[alternative HTML version deleted]]
>
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel

[[alternative HTML version deleted]]

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


Re: [R-pkg-devel] define an environment in .onLoad

2019-01-29 Thread Gábor Csárdi
You don't need .onLoad for this, just put the environment into the
package environment. E.g. simply add

pkg_data <- new.env(parent = emptyenv())

to your package code. Then you can refer to pkg_data from the
functions in the package.

Best,
Gabor

On Tue, Jan 29, 2019 at 9:40 PM Pascal Title  wrote:
>
> Hi,
>
> I am developing an R package where I would like to have a set of names
> defined once, and which could then be queried from within the various
> functions of the package. The way I have currently set this up is to define
> a new environment that contains these names.
>
> So, what I currently have is:
>
> .var <- new.env()
>
> .var$bio <- "bio_"
>
> .var$tmin <- "tmin_"
>
> .var$tmax <- "tmax_"
>
> What I would like is that this environment be created when the R package is
> loaded. That way, default values are automatically in place, and if the
> user would like to change the naming that they use for tmin, for example,
> they would just need to do (for example):
>
>
> .var$tmin <- ‘minTemp_'
>
>
> And then these names can be accessed from within any of the functions, and
> this is unlikely to conflict with any R objects the user is defining.
>
>
> Where I am stuck is how/where to define this new environment such that it
> is made available when the package is loaded. I tried including the
> following in R/zzz.R:
>
>
> .onLoad <- function(libname, pkgname) {
>
>
>   # define a custom environment for defining the naming of variables
>
> .var <- new.env()
>
> # default
>
> .var$bio <- "bio_"
>
> .var$tmin <- "tmin_"
>
> .var$tmax <- "tmax_"
>
> invisible()
>
> }
>
>
> But if I build/install the package, the .var environment is not already
> created. Any suggestions?
>
>
> Thanks!
>
> -Pascal
>
> [[alternative HTML version deleted]]
>
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel

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


[R-pkg-devel] define an environment in .onLoad

2019-01-29 Thread Pascal Title
Hi,

I am developing an R package where I would like to have a set of names
defined once, and which could then be queried from within the various
functions of the package. The way I have currently set this up is to define
a new environment that contains these names.

So, what I currently have is:

.var <- new.env()

.var$bio <- "bio_"

.var$tmin <- "tmin_"

.var$tmax <- "tmax_"

What I would like is that this environment be created when the R package is
loaded. That way, default values are automatically in place, and if the
user would like to change the naming that they use for tmin, for example,
they would just need to do (for example):


.var$tmin <- ‘minTemp_'


And then these names can be accessed from within any of the functions, and
this is unlikely to conflict with any R objects the user is defining.


Where I am stuck is how/where to define this new environment such that it
is made available when the package is loaded. I tried including the
following in R/zzz.R:


.onLoad <- function(libname, pkgname) {


  # define a custom environment for defining the naming of variables

.var <- new.env()

# default

.var$bio <- "bio_"

.var$tmin <- "tmin_"

.var$tmax <- "tmax_"

invisible()

}


But if I build/install the package, the .var environment is not already
created. Any suggestions?


Thanks!

-Pascal

[[alternative HTML version deleted]]

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


[R-pkg-devel] Robj: reading proprietary format - first time packaging

2019-01-29 Thread Ivan Krylov
Hi!

Not being able to find an R package that would let me import an
Origin(R)[0] OPJ file, I found liborigin[1] and used Rcpp (thanks,
Dirk Eddelbuettel!) to create the package which I titled Ropj[2]. Right
now it only understands the absolute minimum of what I needed to
import, but I intend to translate more object types in the future.

I have bundled liborigin as a subdirectory under src, which seems to be
an acceptable practice for small (3 *.cpp files) libraries whose
license (GPL >= 3) matches the package. I'm passing R CMD check
--as-cran, both on my PC and at win-builder (thanks, Uwe Ligges!) [3],
except with a small NOTE that the word OPJ might be misspelled.

Is there anything I might have overlooked that would prevent this
package from being accepted to CRAN? For example, could the presence of
the words Origin(R) or OPJ or OPJ-decoding code itself be a problem
from trademark or licensing point of view?

Should I submit the first version right away or implement all the
features I can in advance?

-- 
Best regards,
Ivan

[0] https://www.originlab.com/viewer/

[1] https://sourceforge.net/projects/liborigin/

[2] https://github.com/aitap/Ropj

[3] https://win-builder.r-project.org/21Zq5r95d3j8/

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