Re: [R] Match ISO 8601 week-of-year numbers to month-of-year numbers on Windows with German locale

2017-01-18 Thread Janko Thyson
Hi Steve,

and thanks so much for taking the time to draft your solution! After
running through it looks like it's EXACTLY what I was looking/hoping
for!

For those interested: I also tried to get this in as a feature request
for the lubridate package >>
https://github.com/hadley/lubridate/issues/506

Here's to open source, social coding and our active user community! :-)

Janko

On Wed, Jan 18, 2017 at 1:35 PM, S Ellison  wrote:
>
>
>> -Original Message-
>> (yw <- format(posix, "%Y-%V"))
>> > # [1] "2015-52" "2015-53" "2016-53" "2016-01"
>>
>> Which, after checking back with a calendar, would give me reason to believe
>> that it using %V does in fact seem to work: it's an input to `format()` and R
>> doesn't seem to ignore it as the correct week numbers (following ISO 8601)
>> are returned.
>
> Unfortunately it does _not_ work as an input to strptime() or as.Date(). Try
> strptime(sprintf("2016-%02d", 1:52), "%Y-%V")
>
> which all return the same (rather arbitrary-looking) date. (R 3.3.1 on 
> Windows 7)
>
> So you can easily extract the week number from a date, but you can't extract 
> the month number from a week number using base R.
>
> What you _could_ do is assign an appropriate weekday in each week and use 
> that day to assign a month. Using the 8601 rules, Thursday seems sensible as 
> that is the weekday used to define the week number. The following crude 
> implementation (which allows some variation in the input string and a custom 
> weekday defaulting to Thursday) seems to work in my UK locale, though I've 
> not spent a lot of time debugging. You should be able to get it to work with 
> minimal tweaking in another locale:
>
> yw.to.month <- function(yw, yearformat="%Y", separator="-", monthformat="%m", 
> weekday=4) {
> # yw  is a character vector assumed to be in %Y-%W" or "%y-%W"
> # form (or with another separator specified by separator)
> # yearformat is a character string used by as.Date to convert the 
> year.
> # separator is the year-week separator string in yw
> # monthformat is the output format, passed to format.Date
> # weekday is the (numerica) day of the week to be used to place the 
> week
> # in a specific month. The default, 4, takes the Thursday.
>
>
> #Get the year as a character vector
> Y <- format(as.Date(yw, yearformat), "%Y")
>
> #Get the date of the first thursday in each year
> Jan01 <- as.Date(sprintf("%s-01-01", Y), "%Y-%m-%d") #constructs 1st 
> Jan for each year
> J1.w <- as.numeric( format(Jan01, "%w") ) #numerical day of week for 
> jan 1st
> date.increment <- ifelse(J1.w > weekday, 7 + weekday - J1.w, weekday 
> - J1.w) #How far to first thursday?
> Thursday1 <- as.Date( Jan01 + date.increment ) #date for first 
> thursday
>
> #Add the week number in yw to get the corresponding Thursday's date
> wknum <- as.numeric( gsub(sprintf(".+%s(.+)", separator), "\\1", yw) )
> Thursdays <- Thursday1 + 7 * (wknum - 1)
>
> #... and convert each Thursday date to month number
> # using supplied monthformat
>
> format( Thursdays, monthformat )
> }
>
> #Examples
> #Construct a collection of "-WW" strings:
> yw <- sprintf("%4d-%02d", rep(2015:2017, each=53), rep(1:53, 3))
> #NB: Week 53 does not exist in all years. e.g 'week 53' of 2016 is 
> week 1 of 2017.
> #But the week number is just used as an offset from the first 
> specified weekday,
> #so the function does returns a valid year and month if the week 
> number is
> #after the year end.
>
> yw.to.month(yw)
>
> yw.to.month(yw, monthformat="%Y-%m")
>
> #Use the month in which the Monday falls:
> yw.to.month(yw, monthformat="%Y-%m", weekday=1)
>
>
>
> Steve E
>
>
>
>
>
>
>
>
> ***
> This email and any attachments are confidential. Any u...{{dropped:8}}

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Match ISO 8601 week-of-year numbers to month-of-year numbers on Windows with German locale

2017-01-13 Thread Janko Thyson
Hi David,

thanks for replying and sorry about the HTML/non-plain-text email (I
forgot to change that, shouldn't have happened).

Might just be me, but reading "The documentation for R datetime format
parameters ?strptime says %V is ignored on input." in the
documentation doesn't really tell me all that much. As a user, I would
read that, not completely understand what this means and thus try to
understand it better by applying it in actual code:

(yw <- format(posix, "%Y-%V"))
> # [1] "2015-52" "2015-53" "2016-53" "2016-01"

Which, after checking back with a calendar, would give me reason to
believe that it using %V does in fact seem to work: it's an input to
`format()` and R doesn't seem to ignore it as the correct week numbers
(following ISO 8601) are returned.

Not wanting to stress this particular aspect any further, though, I
would slightly rephrase my original question: is it possible to use
the ISO 8601 convention for weeknumbers at all (on Windows, using a
German locale setting) and if so, how would I link ISO 8601
weeknumbers to the correct month of the year?

Thanks for help,
Janko

On Thu, Jan 12, 2017 at 8:37 PM, David Winsemius <dwinsem...@comcast.net> wrote:
>
>> On Jan 12, 2017, at 8:14 AM, Janko Thyson <janko.thy...@gmail.com> wrote:
>>
>> Dear list,
>>
>> I'm experiencing problems with converting strings of the format
>> "-" (e.g. 2016-01, 2016-52) to proper POSIX dates which (I
>> think) I need in order to retrieve the month-of-the-year number.
>>
>> Simpler put: I'd like to match week-of-the-year numbers to
>> month-of-the-year numbers. Ideally, the week-of-the-year number would
>> follow the ISO 8601 convention (i.e. format argument "%V") instead of the
>> US (format argument "%U") or UK (format argument "%W") convention.
>>
>> After posting this to Stackoverflow, I have strong reasons to believe that
>> the issue is caused by Windows:
>> http://stackoverflow.com/questions/41616407/match-iso-8601-week-numbers-to-month-of-year-on-windows-with-german-locale/41617215?noredirect=1#comment70436768_41617215
>>
>> Example:
>>
>> # ISO 8601 convention:
>>
>> (yw <- format(posix, "%Y-%V"))
>
> The documentation for R datetime format parameters ?strptime says %V is 
> ignored on input.
>
>
>> # [1] "2015-52" "2015-53" "2016-53" "2016-01"
>> ywd <- sprintf("%s-1", yw)(as.POSIXct(ywd, format = "%Y-%V-%u"))
>
> The documentation for R datetime format parameters ( = ?strptime) says %V is 
> ignored on input.
>
> You should leartn to post plain text to r-help.
>
> --
> David.
>
>
>> # [1]
>> "2015-01-12 CET" "2015-01-12 CET" "2016-01-12 CET" "2016-01-12 CET"#
>> -> utterly wrong!!!
>>
>> # US convention:
>> (yw <- format(posix, "%Y-%U"))# [1] "2015-51" "2015-52" "2016-00" "2016-01"
>> ywd <- sprintf("%s-1", yw)(as.POSIXct(ywd, format = "%Y-%U-%u"))# [1]
>> "2015-12-21 CET" "2015-12-28 CET" NA   "2016-01-04 CET"#
>> -> NA problem for week 00A fellow R user tested this on both macOS and
>> Ubuntu and he didn't encounter the issue:
>>
>> some_dates <- as.POSIXct(c("2015-12-24", "2015-12-31", "2016-01-01",
>> "2016-01-08"))
>> (year_week <- format(some_dates, "%Y %U"))## [1] "2015 51" "2015 52"
>> "2016 00" "2016 01"
>> (year_week_day <- sprintf("%s 1", year_week))## [1] "2015 51 1" "2015
>> 52 1" "2016 00 1" "2016 01 1"
>> (as.POSIXct(year_week_day, format = "%Y %U %u"))## [1] "2015-12-21
>> EST" "2015-12-28 EST" "2016-01-04 EST" "2016-01-04 EST"
>>
>> My session info:
>>
>>> sessionInfo()
>> R version 3.3.2 (2016-10-31)
>> Platform: x86_64-w64-mingw32/x64 (64-bit)
>> Running under: Windows >= 8 x64 (build 9200)
>>
>> locale:[1] LC_COLLATE=German_Germany.1252
>> LC_CTYPE=German_Germany.1252   LC_MONETARY=German_Germany.1252
>> [4] LC_NUMERIC=C   LC_TIME=English_United
>> States.1252
>>
>> attached base packages:[1] stats graphics  grDevices utils
>> datasets  methods   base
>>
>> other attached packages:
>> [1] fva_0.1.0   digest_0.6.10   readxl_0.1.1dplyr_0.5.0
>> plyr_1.8.4  magrittr_1.5
>

[R] Match ISO 8601 week-of-year numbers to month-of-year numbers on Windows with German locale

2017-01-12 Thread Janko Thyson
Dear list,

I'm experiencing problems with converting strings of the format
"-" (e.g. 2016-01, 2016-52) to proper POSIX dates which (I
think) I need in order to retrieve the month-of-the-year number.

Simpler put: I'd like to match week-of-the-year numbers to
month-of-the-year numbers. Ideally, the week-of-the-year number would
follow the ISO 8601 convention (i.e. format argument "%V") instead of the
US (format argument "%U") or UK (format argument "%W") convention.

After posting this to Stackoverflow, I have strong reasons to believe that
the issue is caused by Windows:
http://stackoverflow.com/questions/41616407/match-iso-8601-week-numbers-to-month-of-year-on-windows-with-german-locale/41617215?noredirect=1#comment70436768_41617215

Example:

# ISO 8601 convention:

(yw <- format(posix, "%Y-%V"))# [1] "2015-52" "2015-53" "2016-53" "2016-01"
ywd <- sprintf("%s-1", yw)(as.POSIXct(ywd, format = "%Y-%V-%u"))# [1]
"2015-01-12 CET" "2015-01-12 CET" "2016-01-12 CET" "2016-01-12 CET"#
-> utterly wrong!!!

# US convention:
(yw <- format(posix, "%Y-%U"))# [1] "2015-51" "2015-52" "2016-00" "2016-01"
ywd <- sprintf("%s-1", yw)(as.POSIXct(ywd, format = "%Y-%U-%u"))# [1]
"2015-12-21 CET" "2015-12-28 CET" NA   "2016-01-04 CET"#
-> NA problem for week 00A fellow R user tested this on both macOS and
Ubuntu and he didn't encounter the issue:

some_dates <- as.POSIXct(c("2015-12-24", "2015-12-31", "2016-01-01",
"2016-01-08"))
(year_week <- format(some_dates, "%Y %U"))## [1] "2015 51" "2015 52"
"2016 00" "2016 01"
(year_week_day <- sprintf("%s 1", year_week))## [1] "2015 51 1" "2015
52 1" "2016 00 1" "2016 01 1"
(as.POSIXct(year_week_day, format = "%Y %U %u"))## [1] "2015-12-21
EST" "2015-12-28 EST" "2016-01-04 EST" "2016-01-04 EST"

My session info:

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:[1] LC_COLLATE=German_Germany.1252
LC_CTYPE=German_Germany.1252   LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C   LC_TIME=English_United
States.1252

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

other attached packages:
 [1] fva_0.1.0   digest_0.6.10   readxl_0.1.1dplyr_0.5.0
plyr_1.8.4  magrittr_1.5
 [7] memoise_1.0.0   testthat_1.0.2  roxygen2_5.0.1  devtools_1.12.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.8 lubridate_1.6.0 assertthat_0.1  packrat_0.4.8-1
crayon_1.3.2withr_1.0.2
 [7] R6_2.2.0DBI_0.5-1   stringi_1.1.2   rstudioapi_0.6
tools_3.3.2 stringr_1.1.0  [13] tibble_1.2

Any idea on how to workaround this issue on Windows?

Thanks and best regards,

Janko Thyson

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Inconsistency of S4 dispatch behavior for R6 classes

2014-12-09 Thread Janko Thyson
Dear list,

as a week has passed now after filing an issue for package R6 (
https://github.com/wch/R6/issues/36), I thought it's okay to go ahead and
ask a bigger audience about their opinion/suggestions for a general
solution and/or good workarounds:

Actual questions


1. Shouldn't the fact that [*R6*](https://github.com/wch/R6) classes
inherit from (informal S3) class `R6` allow the definition of S4 methods
for signature arguments of that very class?

2. As this is - AFAICT - not the case, what would be a workaround that is
in line with current S3/S4 standards or that could somewhat be regarded as
best practice in such situations?

Background and example
-

**Reference Classes**

Consider the following example where you would like to define methods that
dispatch on the superclass that all instances of [*Reference Classes*](
https://stat.ethz.ch/R-manual/R-devel/library/methods/html/refClass.html)
inherit from (`envRefClass`):

TestRefClass - setRefClass(TestRefClass, fields= list(.x =
numeric))
setGeneric(foo, signature = x,
  def = function(x) standardGeneric(foo)
)
setMethod(foo, c(x = envRefClass),
  definition = function(x) {
I'm the method for `envRefClass`
})
 try(foo(x = TestRefClass$new()))
[1] I'm the method for `envRefClass`

This inheritance structure is not directly obvious as `class()` won't
reveal that fact:

class(TestRefClass$new())
[1] TestRefClass
attr(,package)
[1] .GlobalEnv

However, a look at the attributes of the class generator object reveals it:

 attributes(TestRefClass)
[... omitted ...]
 Class Methods:
callSuper, copy, export, field, getClass, getRefClass,
import, initFields,
show, trace, untrace, usingMethods


 Reference Superclasses:
envRefClass

[... omitted ...]

That's why the dispatch works

**R6 Classes**

When you would like to a similar thing for R6 classes, things don't seem to
be straight forward even though they initially appear so (compared to
Reference Classes):

TestR6 - R6Class(TestR6, public = list(.x = numeric))
setMethod(foo, c(x = R6),
  definition = function(x) {
I'm the method for `R6`
})
 try(foo(x = TestR6$new()))
Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘foo’ for signature
‘TestR6’

By appearing straight forward I mean that `class()` actually suggests
that all R6 classes inherit from class `R6` that could be used as
superclass for method dispatch:

class(TestR6$new())
[1] TestR6 R6

The help page of `R6Class()` actually reveals that class `R6` is merely
added as an informal S3 class as long as `class = TRUE`. That's also why
there is a warning when trying to define a S4 method for this class.

So then this basically leaves us with two possible options/workarounds:

1. Turn class `R6` into a formal class via `setOldClass()`
2. Have all instances of R6 classes inherit from some other superclass,
say, `.R6`

*Ad 1)*

setOldClass(R6)
 isClass(R6)
[1] TRUE

This works when hacking away in an S3 style at the class table/graph:

dummy - structure(something, class = R6)
 foo(dummy)
[1] I'm the method for `R6`

However, it fails for actual R6 class instances:

 try(foo(x = TestR6$new()))
Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘foo’ for signature
‘TestR6’

*Ad 2)*

.R6 - R6Class(.R6)
TestR6_2 - R6Class(TestR6_2, inherit = .R6, public = list(.x =
numeric))
setMethod(foo, c(x = .R6),
  definition = function(x) {
I'm the method for `.R6`
})
 try(foo(x = TestR6_2$new()))
Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘foo’ for signature
‘TestR6_2’

Conclusion
-

While approach 1 sort operates in a grey area to make S3 and S4 somewhat
compatible, approach 2 seems like a perfectly valid pure S4 solution that
IMO should work. The fact that it's not brought me to raising the question
if there exists an inconsistency in the implementation of R6 classes with
respect to the interaction of informal/formal classes and method dispatch
in R.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fine controlling three dots argument dispatch to functions with identical argument names

2014-11-16 Thread Janko Thyson
Thanks for the info/suggestions!

But note that it's not just a one-step, but a two step dispatching process
with respect to `...`. That is, `foo()` and `bar()` are *not* both called
directly inside `foobar()`: `foobar()` only calls `foo()` which then calls
`bar()`.

I now came up with something along the lines of what Duncan suggested. The
reason I wouldn't want to go with Jeff's approach is that I would want
`foobar()` to remain as generic an interface as possible (the same goes for
`foo()` calling `bar()`).

I.e., I don't want it to have any explicit arguments of subsequently called
functions (e.g. `y_foo`). It should just be able to take any inputs that
subsequently called functions can process (i.e. `foo()` and then in turn
`bar()`) and pass them along accordingly. Of course this would need to be
clearly and well documented for the respective functions.

So here's my current approach. It would be nice to just be able to dispatch
`...` for calls of `do.call()` like so: `do.call(foo, c(x = x, ...))` but
that way a nested structure of `...` gets flattened out (see respective
lines in `foobar()`). That's why I need to resort to `do.call(foo, c(x =
x, threedots$args_foo, threedots[-idx]))`. What do you think of it?

foobar - function(x, ...) {
  message(foobar --)
  message(foobar/threedots)
  threedots - list(...)
  try(print(threedots))
  message(foobar/combined args)
  try(print(c(x, threedots)))
  ## -- list gets flattened (i.e. `args_foo.y` instead of nested structure)
  ## -- that's why subsequent functions will not recognize their
arguments
  ## from it
  if (any(idx - names(threedots) %in% args_foo)) {
do.call(foo, c(x = x, threedots$args_foo, threedots[-idx]))
  } else {
foo(x = x, ...)
  }
}
foo - function(x, y = some character, ...) {
  message(foo --)
  message(foo/threedots)
  threedots - list(...)
  try(print(threedots))
  message(foo/y)
  try(print(y))
  if (any(idx - names(threedots) %in% args_bar)) {
do.call(bar, c(x = x, threedots$args_bar, threedots[-idx]))
  } else {
bar(x = x, ...)
  }
}
bar - function(x, y = TRUE, ...) {
  message(bar --)
  message(bar/threedots)
  try(print(list(...)))
  message(bar/y)
  try(print(y))
  return(paste0(hello: , x))
}

foobar(x = John Doe, args_foo = list(y = hello world!))
foobar(x = John Doe, args_bar = list(y = FALSE))
foobar(x = John Doe,
   args_foo = list(y = hello world!),
   args_bar = list(y = FALSE)
)

Best regards and thanks,
Janko

On Sat, Nov 15, 2014 at 6:10 PM, Duncan Murdoch murdoch.dun...@gmail.com
wrote:

 On 15/11/2014, 11:26 AM, Jeff Newmiller wrote:
  AFAIK You have to alter the name of at least one of the y arguments as
 used by foobar, and anyone calling foobar has to read about that in the
 help file. That is only one y can be in  e.g.
 
  foobar - function( x, y_foo, ... ) {
foo( x, y=y_foo, ... )
bar( x, ... )
  }
 

 That's the best solution.  There is another one:  you can put

 args - list(...)

 into foobar(), and then do whatever you like to the args vector, and put
 together calls to foo() and bar() using do.call().  But this is hard to
 read and easy to get wrong, so I recommend Jeff's simple solution.

 Duncan Murdoch

 
 
 ---
  Jeff NewmillerThe .   .  Go
 Live...
  DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live
 Go...
Live:   OO#.. Dead: OO#..  Playing
  Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
  /Software/Embedded Controllers)   .OO#.   .OO#.
 rocks...1k
 
 ---
  Sent from my phone. Please excuse my brevity.
 
  On November 15, 2014 6:49:41 AM PST, Janko Thyson 
 janko.thy...@gmail.com wrote:
  Dear list,
 
  I wonder if there's a clever way to fine control the exact way
  arguments
  are dispatched via R's three dots argument 
 
  Consider the following use case:
 
  - you have a function foobar() that calls foo() which in turn calls
  bar()
  - *both* foo() and bar() have an argument that's called y, but they
  each
have a *different meaning*
  - in the call to foobar(), you would like to say here's the y for
  foo()
  and here's the y for bar(). *That's what I would like to accomplish*.
 
  If you simply call foobar(x = John Doe, y = hello world), y only
  get's
  dispatched to foo() as in the call to bar() things would have to be
  explicit in order to be dispatched (i.e. the call would have to be
  bar(x =
  x, y = y) instead of bar(x = x, ...):
 
  foo - function(x, y = some character, ...) {
   message(foo --)
   message(foo/threedots)
   try(print(list(...)))
   message(foo/y)
   try(print(y))
   bar(x = x, ...)}
  bar - function(x, y = TRUE, ...) {
   message(bar --)
   message(bar/threedots)
   try(print(list(...)))
   message(bar/y

Re: [R] Fine controlling three dots argument dispatch to functions with identical argument names

2014-11-16 Thread Janko Thyson
{...}.
#' @example inst/examples/existsNested.r
#' @seealso \code{\link[foo.package]{foo}}
#' @export
foobar - function(x, ...) {
  withThreedots(foo, x = x, ...)
}

foo - function(x = x, y = some text, ...) {
  message(foo/y)
  print(y)
  withThreedots(bar, x = x, ...)
}
bar - function(x = x, y = 1, ...) {
  message(bar/y)
  print(y)
  withThreedots(downTheLine, x = x, ...)
}
downTheLine - function(x = x, y = list(), ...) {
  message(downTheLine/y)
  print(y)
}

*Apply  //*

foobar(x = 10)
foobar(x = 10, args_foo = list(y = hello world!))
foobar(x = 10, args_bar = list(y = 10))
foobar(x = 10, args_downTheLine = list(y = list(a = TRUE)))

foobar(x = 10,
   args_foo = list(y = hello world!),
   args_bar = list(y = 10),
   args_downTheLine = list(y = list(a = TRUE))
)

On Sun, Nov 16, 2014 at 7:54 PM, Jeff Newmiller jdnew...@dcn.davis.ca.us
wrote:

 You have some interesting ideas about what makes for improvements in
 parameter interfaces. Wrapping the arguments into a list is like creating
 an object to represent all of them, except that you don't have the benefits
 of a class to go with that cognitive shift. And if making classes to hold
 parameters were appropriate wouldn't you have already done so in the foo
 and bar interfaces? That is a heavyweight approach that doesn't always make
 sense.

 I agree with Duncan that each time you define a function you are defining
 an interface that should stand on its own... the user should be able to
 associate unique names with unique behaviors. From this perspective, your
 reluctance to define a unified set of uniquely-named parameters for each of
 foobar and (and apparently foo) seems illogical.
 ---
 Jeff NewmillerThe .   .  Go Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live
 Go...
   Live:   OO#.. Dead: OO#..  Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
 /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
 ---
 Sent from my phone. Please excuse my brevity.

 On November 16, 2014 8:42:20 AM PST, Janko Thyson janko.thy...@gmail.com
 wrote:
 Thanks for the info/suggestions!
 
 But note that it's not just a one-step, but a two step dispatching
 process
 with respect to `...`. That is, `foo()` and `bar()` are *not* both
 called
 directly inside `foobar()`: `foobar()` only calls `foo()` which then
 calls
 `bar()`.
 
 I now came up with something along the lines of what Duncan suggested.
 The
 reason I wouldn't want to go with Jeff's approach is that I would want
 `foobar()` to remain as generic an interface as possible (the same goes
 for
 `foo()` calling `bar()`).
 
 I.e., I don't want it to have any explicit arguments of subsequently
 called
 functions (e.g. `y_foo`). It should just be able to take any inputs
 that
 subsequently called functions can process (i.e. `foo()` and then in
 turn
 `bar()`) and pass them along accordingly. Of course this would need to
 be
 clearly and well documented for the respective functions.
 
 So here's my current approach. It would be nice to just be able to
 dispatch
 `...` for calls of `do.call()` like so: `do.call(foo, c(x = x, ...))`
 but
 that way a nested structure of `...` gets flattened out (see respective
 lines in `foobar()`). That's why I need to resort to `do.call(foo,
 c(x =
 x, threedots$args_foo, threedots[-idx]))`. What do you think of it?
 
 foobar - function(x, ...) {
   message(foobar --)
   message(foobar/threedots)
   threedots - list(...)
   try(print(threedots))
   message(foobar/combined args)
   try(print(c(x, threedots)))
 ## -- list gets flattened (i.e. `args_foo.y` instead of nested
 structure)
   ## -- that's why subsequent functions will not recognize their
 arguments
   ## from it
   if (any(idx - names(threedots) %in% args_foo)) {
 do.call(foo, c(x = x, threedots$args_foo, threedots[-idx]))
   } else {
 foo(x = x, ...)
   }
 }
 foo - function(x, y = some character, ...) {
   message(foo --)
   message(foo/threedots)
   threedots - list(...)
   try(print(threedots))
   message(foo/y)
   try(print(y))
   if (any(idx - names(threedots) %in% args_bar)) {
 do.call(bar, c(x = x, threedots$args_bar, threedots[-idx]))
   } else {
 bar(x = x, ...)
   }
 }
 bar - function(x, y = TRUE, ...) {
   message(bar --)
   message(bar/threedots)
   try(print(list(...)))
   message(bar/y)
   try(print(y))
   return(paste0(hello: , x))
 }
 
 foobar(x = John Doe, args_foo = list(y = hello world!))
 foobar(x = John Doe, args_bar = list(y = FALSE))
 foobar(x = John Doe,
args_foo = list(y = hello world!),
args_bar = list(y = FALSE)
 )
 
 Best regards and thanks,
 Janko
 
 On Sat, Nov 15, 2014 at 6:10 PM, Duncan Murdoch
 murdoch.dun...@gmail.com
 wrote:
 
  On 15/11/2014, 11

Re: [R] Lexical scoping/calling stack issue: R fails to recognize an argument's default value

2014-11-15 Thread Janko Thyson
Ok, I have to admit: that was a really stupid mistake :-/

I unintentionally had a trailing `,` in the call to `nestr::setNested()`
inside `optionr::setAnywhereOption()`

Here's a much simpler illustration:

*Definitions* //

setGeneric(
  name = setAnywhereOption,
  signature = id,
  def = function(id, ...) standardGeneric(setAnywhereOption)
)
setMethod(
  f = setAnywhereOption,
  signature = signature(id = character),
#  definition = function(id, ...) setNested(id = id)
  ## -- works
#  definition = function(id, ...) setNested(id = id, ...)
  ## -- works
  definition = function(id, ...) setNested(id = id,)
  ## -- this leads to things get messed up with argument's default
values
  ## -- so the trailing `,` was causing the problem!
)
setGeneric(
  name = setNested,
  signature = id,
  def = function(id, ...) standardGeneric(setNested)
)
setMethod(
  f = setNested,
  signature = signature(id = character),
  definition = function(id, ...) {

  if (FALSE) {
## Omitted
  } else {
setShinyReactive(id = basename(id), ...)
  }

})
setShinyReactive - function(
  id,
  lazy = FALSE,
  is_lazy = FALSE,
  push = FALSE,
  typed = FALSE,
  strict_set = c(0, 1, 2),
  ...
  ) {

  ###
  ## DEBUG ##
  ###
  message(DEBUG/setShinyReactive/threedots)
  print(list(...))
  message(DEBUG/setShinyReactive/push)
  print(push)
  message(DEBUG/setShinyReactive/lazy)
  try(print(lazy))
  ## -- strangely, R does not seem to like the name `lazy`
  message(DEBUG/setShinyReactive/is_lazy)
  print(is_lazy)
  ## -- this works
  lazy - is_lazy
  message(DEBUG/setShinyReactive/lazy)
  print(lazy)

  TRUE

}

*Apply //*

setAnywhereOption(id = test)
# DEBUG/setShinyReactive/threedots
# list()
# DEBUG/setShinyReactive/push
# [1] FALSE
# DEBUG/setShinyReactive/lazy
# Error in print(lazy) : argument is missing, with no default
# DEBUG/setShinyReactive/is_lazy
# [1] FALSE
# DEBUG/setShinyReactive/lazy
# [1] FALSE
# [1] TRUE
setAnywhereOption(id = test, push = TRUE)
setAnywhereOption(id = test, lazy = TRUE)

*Actual cause / solution //*

Removing the trailing `,` in the method definition of `setAnywhereOption()`:

setMethod(
  f = setAnywhereOption,
  signature = signature(id = character),
  definition = function(id, ...) setNested(id = id)
  ## -- works
#  definition = function(id, ...) setNested(id = id,)
  ## -- this leads to things get messed up with argument's default
values
  ## -- so the trailing `,` was causing the problem!
)

setAnywhereOption(id = test)
# DEBUG/setShinyReactive/threedots
# list()
# DEBUG/setShinyReactive/push
# [1] FALSE
# DEBUG/setShinyReactive/lazy
# [1] FALSE
# DEBUG/setShinyReactive/is_lazy
# [1] FALSE
# DEBUG/setShinyReactive/lazy
# [1] FALSE
# [1] TRUE

Now it works just fine. Also stated this as an answer as potential
reference for others that might run into similar problems:
http://stackoverflow.com/questions/26940474/lexical-scoping-calling-stack-issue-r-fails-to-recognize-an-arguments-defaul

Thanks for everyone that answered/took the time to have a look at the code
- and sorry for having thrown a complicated example at you!
It was just that at first I didn't see the wood for the trees and I thought
that the problem was caused by this very calling stack structure (spread
across three different packages).

Best regards and happy coding,
Janko

On Sat, Nov 15, 2014 at 2:06 AM, Janko Thyson janko.thy...@gmail.com
wrote:

 Thanks. I will try to further simplify the example.

 On Sat, Nov 15, 2014 at 2:01 AM, Jeff Newmiller jdnew...@dcn.davis.ca.us
 wrote:

 While you appear to have been thorough in providing access to your code,
 I don't think I will install a bunch of your dev code to debug it for you.
 The Posting Guide does say your example should be minimal, and IMO this
 doesn't fit that description. You should extract enough generic functions
 to replicate the structure of the call tree in a single short example.

 I suppose there could be a bug in the parameter handling, but are you
 sure every calling point is including the ... argument that should be?

 My second blind point is that visibility of package variables does follow
 a complicated path, but there are good descriptions available, such as [1]
 or [2].

 If you do think you have found a bug, the R Core team will want a minimal
 reproducible example, and you should read the Posting Guide on bug
 reporting to make sure your issue gets addressed.

 [1] http://obeautifulcode.com/R/How-R-Searches-And-Finds-Stuff/
 [2] http://adv-r.had.co.nz/Environments.html

 ---
 Jeff Newmiller

[R] Fine controlling three dots argument dispatch to functions with identical argument names

2014-11-15 Thread Janko Thyson
Dear list,

I wonder if there's a clever way to fine control the exact way arguments
are dispatched via R's three dots argument 

Consider the following use case:

   - you have a function foobar() that calls foo() which in turn calls bar()
   - *both* foo() and bar() have an argument that's called y, but they each
   have a *different meaning*
   - in the call to foobar(), you would like to say here's the y for foo()
   and here's the y for bar(). *That's what I would like to accomplish*.

If you simply call foobar(x = John Doe, y = hello world), y only get's
dispatched to foo() as in the call to bar() things would have to be
explicit in order to be dispatched (i.e. the call would have to be bar(x =
x, y = y) instead of bar(x = x, ...):

foo - function(x, y = some character, ...) {
  message(foo --)
  message(foo/threedots)
  try(print(list(...)))
  message(foo/y)
  try(print(y))
  bar(x = x, ...)}
bar - function(x, y = TRUE, ...) {
  message(bar --)
  message(bar/threedots)
  try(print(list(...)))
  message(bar/y)
  try(print(y))
  return(paste0(hello: , x))}
foobar - function(x, ...) {
  message(foobar --)
  message(foobar/threedots)
  try(print(list(...)))
  foo(x = x, ...)}

foobar(x = John Doe, y = hi there)# foobar --#
foobar/threedots# $y# [1] hi there# # foo --# foo/threedots#
list()# foo/y# [1] hi there# bar --# bar/threedots# list()#
bar/y# [1] TRUE# [1] hello: John Doe

What I conceptionally would like to be able to do is something like this:

foobar(x = John Doe, y_foo = hello world!, y_bar = FALSE)

Here's an approach that works but that also feels very odd:

foo - function(x, y = some character, ...) {
  message(foo --)
  message(foo/threedots)
  try(print(list(...)))
  message(foo/y)
  arg - paste0(y_, sys.call()[[1]])
  if (arg %in% names(list(...))) {
y - list(...)[[arg]]
  }
  try(print(y))
  bar(x = x, ...)}
bar - function(x, y = TRUE, ...) {
  message(bar --)
  message(bar/threedots)
  try(print(list(...)))
  message(bar/y)
  arg - paste0(y_, sys.call()[[1]])
  if (arg %in% names(list(...))) {
y - list(...)[[arg]]
  }
  try(print(y))
  return(paste0(hello: , x))}

foobar(x = John Doe, y_foo = hello world!, y_bar = FALSE)# foobar
--# foobar/threedots# $y_foo# [1] hello world!# # $y_bar#
[1] FALSE# # foo --# foo/threedots# $y_foo# [1] hello
world!# # $y_bar# [1] FALSE# # foo/y# [1] hello world!# bar
--# bar/threedots# $y_foo# [1] hello world!# # $y_bar# [1]
FALSE# # bar/y# [1] FALSE# [1] hello: John Doe

How would you go about implementing something like this?

I also played around with S4 method dispatch to see if I could define
methods for a signature argument ..., but that didn't go too well (and it's
probably a very bad idea anyway):

setGeneric(
  name = foo,
  signature = c(x, ...),
  def = function(x, ...) standardGeneric(foo)  )
setMethod(
  f = foo,
  signature = signature(x = character, ... = MyThreeDotsForBar),
 definition = function(x, ...) bar(x = x))## -- does not work

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Lexical scoping/calling stack issue: R fails to recognize an argument's default value

2014-11-14 Thread Janko Thyson
Dear list,

I just encountered a behavior that I've never seen before:

Is it possible, that certain argument names (lazy in my case) are
special/reserved and thus would lead to unexpected behavior when a calling
stack is involved that spreads across functions of three different
packages: optionr::setAnywhereOptions() calls nestr::setNested() calls
reactr::setShinyReactive()?

Or is there something I'm generally missing with respect the combination of
lexical scoping/the frame stack, S4 and default values of function
arguments.

Running the following code leads to a situation where the default value of
`lazy` in `reactr::setShinyReactive()` is not properly recognized while
others (e.g. `push`) are recognized just fine:

require(devtools)
devtools::install_github(Rappster/conditionr)
devtools::install_github(Rappster/nestr)
devtools::install_github(Rappster/optionr)
require(optionr)

container - initializeOptionContainer(overwrite = TRUE)
expect_true(setAnywhereOption(id = x_1, value = TRUE, reactive = TRUE))
expect_equal(getAnywhereOption(id = x_1), TRUE)
expect_true(res - setAnywhereOption(id = x_2,
  value = reactr::reactiveExpression(
!getAnywhereOption(id = x_1)
  ),
  reactive = TRUE))

The current version of `setShinyReactive()` contains a debugging section
that prints these status messages (the actual code:
https://github.com/Rappster/reactr/blob/bug-28/R/setShinyReactive.r#L196)

DEBUG/push/before[1] FALSE
DEBUG/lazy/before
Error in print(lazy) : argument is missing, with no default
DEBUG/is_lazy/before[1] FALSE
DEBUG/lazy/after[1] FALSE

It also contains my current workaround: also include an argument with
name `is_lazy` (whose default)
value is recognized again) and then run `lazy - is_lazy`.

You can also find this information in this Stackoverflow post:
http://stackoverflow.com/questions/26940474/lexical-scoping-issue-r-fails-to-recognize-an-arguments-default-value

Thanks a lot for everyone that can shed some light on this!


Best regards,
Janko

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Lexical scoping/calling stack issue: R fails to recognize an argument's default value

2014-11-14 Thread Janko Thyson
Hi Duncan,

thanks for answering and I'm very sorry: I was a bit too quick with letting
the example go.

This should be self-contained now:

require(devtools)

## Dependencies //
devtools::install_github(Rappster/conditionr)
devtools::install_github(Rappster/typr)
devtools::install_github(Rappster/nestr)
devtools::install_github(Rappster/reactr, ref = bug-28)
## Actual package //
devtools::install_github(Rappster/optionr)
require(optionr)

path - file.path(tempdir(), test)
create(path, description = getOption(devtools.desc), check = FALSE,
  rstudio = TRUE)
setwd(path)

container - initializeOptionContainer(overwrite = TRUE)
setAnywhereOption(id = x_1, value = TRUE, reactive = TRUE)
getAnywhereOption(id = x_1)
setAnywhereOption(id = x_2,
  value = reactr::reactiveExpression(
!getAnywhereOption(id = x_1)
  ),
  reactive = TRUE)

getAnywhereOption(id = x_1)
getAnywhereOption(id = x_2)

Thanks a lot should you take the time to look into this,
Janko

On Sat, Nov 15, 2014 at 1:13 AM, Duncan Murdoch murdoch.dun...@gmail.com
wrote:

 On 14/11/2014, 6:51 PM, Janko Thyson wrote:
  Dear list,
 
  I just encountered a behavior that I've never seen before:
 
  Is it possible, that certain argument names (lazy in my case) are
  special/reserved and thus would lead to unexpected behavior when a
 calling
  stack is involved that spreads across functions of three different
  packages: optionr::setAnywhereOptions() calls nestr::setNested() calls
  reactr::setShinyReactive()?

 No.

 
  Or is there something I'm generally missing with respect the combination
 of
  lexical scoping/the frame stack, S4 and default values of function
  arguments.
 
  Running the following code leads to a situation where the default value
 of
  `lazy` in `reactr::setShinyReactive()` is not properly recognized while
  others (e.g. `push`) are recognized just fine:
 
  require(devtools)
  devtools::install_github(Rappster/conditionr)
  devtools::install_github(Rappster/nestr)
  devtools::install_github(Rappster/optionr)
  require(optionr)
 
  container - initializeOptionContainer(overwrite = TRUE)
  expect_true(setAnywhereOption(id = x_1, value = TRUE, reactive = TRUE))
  expect_equal(getAnywhereOption(id = x_1), TRUE)
  expect_true(res - setAnywhereOption(id = x_2,
value = reactr::reactiveExpression(
  !getAnywhereOption(id = x_1)
),
reactive = TRUE))
 
  The current version of `setShinyReactive()` contains a debugging section
  that prints these status messages (the actual code:
  https://github.com/Rappster/reactr/blob/bug-28/R/setShinyReactive.r#L196
 )
 
  DEBUG/push/before[1] FALSE
  DEBUG/lazy/before
  Error in print(lazy) : argument is missing, with no default
  DEBUG/is_lazy/before[1] FALSE
  DEBUG/lazy/after[1] FALSE
 
  It also contains my current workaround: also include an argument with
  name `is_lazy` (whose default)
  value is recognized again) and then run `lazy - is_lazy`.
 
  You can also find this information in this Stackoverflow post:
 
 http://stackoverflow.com/questions/26940474/lexical-scoping-issue-r-fails-to-recognize-an-arguments-default-value
 
  Thanks a lot for everyone that can shed some light on this!

 Sorry, I don't use Stackoverflow.  If you don't get a more useful answer
 from someone else, please simplify the question and post a
 self-contained version to R-help.

 Duncan Murdoch

 
 
  Best regards,
  Janko
 
[[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Lexical scoping/calling stack issue: R fails to recognize an argument's default value

2014-11-14 Thread Janko Thyson
Thanks. I will try to further simplify the example.

On Sat, Nov 15, 2014 at 2:01 AM, Jeff Newmiller jdnew...@dcn.davis.ca.us
wrote:

 While you appear to have been thorough in providing access to your code, I
 don't think I will install a bunch of your dev code to debug it for you.
 The Posting Guide does say your example should be minimal, and IMO this
 doesn't fit that description. You should extract enough generic functions
 to replicate the structure of the call tree in a single short example.

 I suppose there could be a bug in the parameter handling, but are you sure
 every calling point is including the ... argument that should be?

 My second blind point is that visibility of package variables does follow
 a complicated path, but there are good descriptions available, such as [1]
 or [2].

 If you do think you have found a bug, the R Core team will want a minimal
 reproducible example, and you should read the Posting Guide on bug
 reporting to make sure your issue gets addressed.

 [1] http://obeautifulcode.com/R/How-R-Searches-And-Finds-Stuff/
 [2] http://adv-r.had.co.nz/Environments.html
 ---
 Jeff NewmillerThe .   .  Go Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live
 Go...
   Live:   OO#.. Dead: OO#..  Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
 /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
 ---
 Sent from my phone. Please excuse my brevity.

 On November 14, 2014 3:51:16 PM PST, Janko Thyson janko.thy...@gmail.com
 wrote:
 Dear list,
 
 I just encountered a behavior that I've never seen before:
 
 Is it possible, that certain argument names (lazy in my case) are
 special/reserved and thus would lead to unexpected behavior when a
 calling
 stack is involved that spreads across functions of three different
 packages: optionr::setAnywhereOptions() calls nestr::setNested() calls
 reactr::setShinyReactive()?
 
 Or is there something I'm generally missing with respect the
 combination of
 lexical scoping/the frame stack, S4 and default values of function
 arguments.
 
 Running the following code leads to a situation where the default value
 of
 `lazy` in `reactr::setShinyReactive()` is not properly recognized while
 others (e.g. `push`) are recognized just fine:
 
 require(devtools)
 devtools::install_github(Rappster/conditionr)
 devtools::install_github(Rappster/nestr)
 devtools::install_github(Rappster/optionr)
 require(optionr)
 
 container - initializeOptionContainer(overwrite = TRUE)
 expect_true(setAnywhereOption(id = x_1, value = TRUE, reactive =
 TRUE))
 expect_equal(getAnywhereOption(id = x_1), TRUE)
 expect_true(res - setAnywhereOption(id = x_2,
   value = reactr::reactiveExpression(
 !getAnywhereOption(id = x_1)
   ),
   reactive = TRUE))
 
 The current version of `setShinyReactive()` contains a debugging
 section
 that prints these status messages (the actual code:
 https://github.com/Rappster/reactr/blob/bug-28/R/setShinyReactive.r#L196)
 
 DEBUG/push/before[1] FALSE
 DEBUG/lazy/before
 Error in print(lazy) : argument is missing, with no default
 DEBUG/is_lazy/before[1] FALSE
 DEBUG/lazy/after[1] FALSE
 
 It also contains my current workaround: also include an argument with
 name `is_lazy` (whose default)
 value is recognized again) and then run `lazy - is_lazy`.
 
 You can also find this information in this Stackoverflow post:
 
 http://stackoverflow.com/questions/26940474/lexical-scoping-issue-r-fails-to-recognize-an-arguments-default-value
 
 Thanks a lot for everyone that can shed some light on this!
 
 
 Best regards,
 Janko
 
[[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] S4 Reference Classes: undesired behavior when calling method '$field()'

2013-03-20 Thread Janko Thyson
Dear list,

I came across a behavior that IMHO is somewhat undesired when calling 
'$field()':
If the field name whose value you're trying to get is *not* a valid 
field of the Reference Class, then R doesn't stop there with an error, 
but scans through all enclosing environments/frames. The result is 
something similar to calling '|get(objname, inherits=TRUE)|' when 
you'd actually expect something like ' get(objname, inherits=FALSE)' 
to be the default (at least I do) in order to avoid undesired retrieval 
results.

Here's a little illustration of the behavior:
http://stackoverflow.com/questions/15529251/avoiding-consideration-of-enclosing-frames-when-retrieving-field-value-of-a-s4-r

Best regards,
Janko

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Appending BSON arrays in MongoDB with package 'rmongodb'

2013-01-24 Thread Janko Thyson

Dear list,

I simply can't figure out how to append an BSON array in MongoDB (with 
package 'rmongodb') using either the '$push' or '$addToSet' operator.


It's sort of the last missing puzzle piece regarding CRUD operations, so 
any hint will be greatly appreciated! Below you'll find a link to an SO 
post where I provided a reproducible example and additional information 
regarding MongoDB: 
http://stackoverflow.com/questions/14489612/problems-with-mongodbs-push-operator-rmongodb


Thanks a lot and best regards,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Workarounds to Rd file name conflict when extending a S4 method of some other package

2012-11-30 Thread Janko Thyson

Dear list,

// IN SHORT //
What are possible workarounds to consolidate documentation for S4 
methods that are scattered across different packages (generic and some 
custom methods in one package, additional custom methods in another 
package) in a *single* Rd help file while using package 'roxygen2' to 
generate the actual Rd files?


// ADDITIONAL INFORMATION //
First of, here are the three facts that cause my problem:

1) I'd like the software, i.e. the packages, that I write to be as 
extendable as possible

2) I pretty much ended up using S4 functionality in everything I do
3) I'm a big fan of in-file documentation and package 'roxygen2' does 
a wonderful job in helping me out keeping my Rd help files synced


That being said, it is a quite common scenario that some package (say 
'pkga') contains the *generic* method/function 'foo()' as well as *some* 
custom methods (for different data types of the available signature 
arguments).


Now, let's suppose that someone using 'pkga' and building a new package 
(say 'pkgb') would like to build upon the generic method 'pkga::foo()' 
and provide some more custom methods for it. When he sticks to the 
suggested workflow (especially with respect to the way the roxygen2 code 
is written), then R CMD check will rightly(!) complain that an Rd file 
with the respective name (generated by 'roxygenize()') already exists 
(because it is already part of 'pkga').


My question is hence twofold:
1) What would be possible workarounds that allow me to a) keep using 
'roxygen2' and link documentation of pkga::foo() with that of 
pkgb::foo() (as they do belong together conecptionally)
2) Is there a need to address this problem on a higher level in the 
future? My feeling is that more people are starting to use S4 which, 
IMHO, is a good thing as it allows to systematically build upon code of 
other programmers. But then I guess we would need some sort of an 
inter-package check and/or help-file consolidation to present the user 
a single source of documentation for some S4 method.


I tried to illustrate the problem with actual code in this post at 
Stackoverflow: 
http://stackoverflow.com/questions/13137912/rd-file-name-conflict-when-s4-generic-and-methods-are-not-in-the-same-package


Best regards,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Possible bug in class 'POSIXlt' when including microseconds?

2012-07-30 Thread Janko Thyson
Dear list,

I'm a bit puzzled by an ambiguity with respect to the representation of 
micro-/milliseconds when using 'POSIXlt' objects.

It seems that the last digit of  the 'sec' attribute sometimes seems to 
differ from the digits shown when printing the 'POSIXlt' object. You'll 
find a little SO post with some example code here: 
http://stackoverflow.com/questions/11725517/ambiguity-with-posixlt-representation-when-microseconds-are-included.

In case you don't want to have a look at that, here's another short example:

|opts-  options(digits.secs=6)
x-  2012-07-30 12:10:09.123123

posix-  as.POSIXlt(x,  tz=Europe/Berlin)

  posix
[1]  2012-07-30 12:10:09.123122 Europe/Berlin

  posix$sec
[1]  9.123123
|

# Manually changing the 'sec' attribute

|posix$sec-  9.123122
  posix
[1]  2012-07-30 12:10:09.123122 Europe/Berlin
# Still '.123122'

posix$sec-  9.123124
  posix
[1]  2012-07-30 12:10:09.123124 Europe/Berlin
# Now it's '.123124' in both 'representations'
|


Thanks a lot for any clarification on this!
Janko

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Feature request: 'file.path()' accepting an input vector

2012-06-28 Thread Janko Thyson

Dear list,

I have a small feature request regarding the implementation of 
'file.path()':


It'd be great if 'file.path()' would allow to specify an input *vector* 
instead of solely rely on a specification via the three dot argument.


AFAIU, currently it's only possible to manually specify each path 
component via the three dot argument:

 file.path(letters[1], letters[2], letters[3])
[1] a/b/c

Providing a vector object will result in the same vector being returned, 
instead of a slash separated scalar:

 file.path(letters[1:3])
[1] a b c

It'd be great if the last call would have this result:
 file.path(letters[1:3])
[1] a/b/c

If that's already possible, I'd appreciate a pointer. If not: thanks a 
lot for considering this,


Best regards,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Feature request: 'file.path()' accepting an input vector

2012-06-28 Thread Janko Thyson

Clearly you're right - and polite... as always

I asked the question because I wanted to avoid 'paste(x, collapse=/)' 
and 'do.call(file.path, as.list(x))' because it's less efficient than 
'file.path()' and '?file.path()' explicitly recommends *not* using 
'paste()' for putting together file paths.


On 28.06.2012 12:10, Prof Brian Ripley wrote:

On 28/06/2012 10:40, Janko Thyson wrote:

Dear list,

I have a small feature request regarding the implementation of
'file.path()':


Clearly you have not read where and how to make feature requests 
(R-devel list or Wishlist on bugs.r-project.org).


It'd be great if 'file.path()' would allow to specify an input *vector*
instead of solely rely on a specification via the three dot argument.

AFAIU, currently it's only possible to manually specify each path
component via the three dot argument:
  file.path(letters[1], letters[2], letters[3])
[1] a/b/c

Providing a vector object will result in the same vector being returned,
instead of a slash separated scalar:
  file.path(letters[1:3])
[1] a b c

It'd be great if the last call would have this result:
  file.path(letters[1:3])
[1] a/b/c

If that's already possible, I'd appreciate a pointer. If not: thanks a
lot for considering this,


It's not going ever to be possible: it does what it is intended and 
documented to do with a single vector, and people rely on the existing 
behaviour. OTOH


paste(x, collapse=/)

does what you want (you could use .Platform$file.sep for maximal 
portability).  Or you could use do.call(file.path, as.list(x))





Best regards,
Janko





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Bug with memory allocation when loading Rdata files iteratively?

2012-02-09 Thread Janko Thyson
Dear list,

when iterating over a set of Rdata files that are loaded, analyzed and 
then removed from memory again, I experience a *significant* increase in 
an R process' memory consumption (killing the process eventually).

It just seems like removing the object via |rm()| and firing |gc()| do 
not have any effect, so the memory consumption of each loaded R object 
cumulates until there's no more memory left :-/

Possibly, this is also related to XML package functionality (mainly 
|htmlTreeParse| and |getNodeSet|), but I also experience the described 
behavior when simply iteratively loading and removing Rdata files.

I've put together a little example that illustrates the memory 
ballooning mentioned above which you can find here: 
http://stackoverflow.com/questions/9220849/significant-memory-issue-in-r-when-iteratively-loading-rdata-files-killing-the

Is this a bug? Any chance of working around this?

Thanks a lot and best regards,
Janko



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Update MS Windows PATH variable based on a R script

2011-12-08 Thread Janko Thyson
This is a very very very late follow up, but I remember asking this 
question and just stumbled across an answer by Yihui. Check his file 
'add-R-path-win.R' script which you can find at 
https://github.com/yihui/lyx/blob/master/README.md


Very cool, thanks Yihui.

Regards,
Janko

On 29.06.2011 20:58, Duncan Murdoch wrote:

On 29/06/2011 2:24 PM, Janko Thyson wrote:

Dear list,

this is not directly an R question, but it is somewhat related to R
aspects, so I hope it's okay to post it here:

I'd like to update my windows PATH based on a script routine in order to
make sure that crucial components are contained. Much like what happens
at the installation of Rtools (if desired). Now, can you do that from
within R or do I need some sort of windows batch file or something like
AutoIt script (http://www.autoitscript.com/site/autoit/)? If so, what
would I need to put in there?


You need to set the registry entry if you want a persistent change to 
the PATH.  Sys.setenv just modifies R's copy of the PATH.  Child 
processes will see the modifications, but they don't last beyond the R 
session.


You'll have to check MS docs to find which registry entry to mess 
with.  Alternatively, if you feel lucky, just use Control Panel to set 
some strange path, then see where your change showed up using regedit.


R doesn't have a built-in function to write to the registry, but there 
are various utilities available outside of R to do it.


Duncan Murdoch



Here's what I tried in R:

unlist(strsplit(Sys.getenv(PATH), ;))
PATH.0- Sys.getenv(PATH)
PATH.1- paste(PATH.0, C:\\blabla\bin)
Sys.setenv(PATH=PATH.1)
unlist(strsplit(Sys.getenv(PATH), ;))

The changes seem to be reflected, but when I check my PATH the new entry
isn't there. I guess there is no actual feedback to Windows system
environment variable and that's exactly what I would like to accomplish

Thanks a lot for any advice,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] making changes to global variables in functions

2011-12-07 Thread Janko Thyson
Basically, I see two options here:

1) Using environments

# Temp environment
env - new.env(parent=emptyenv())
env$state1 - list(n=100, won=0)
env$state2 - list(n=100, won=0)

fight2 - function(stateA, stateB, envir){
#  get(stateA, envir=envir)$n - 50
 # The above is what you would want to do, but
 # 'get-' is not defined, so:
 temp - get(stateA, envir=envir)
 temp$n - 50
 assign(stateA, value=temp, envir=envir)

 # Same for stateB
 temp - get(stateB, envir=envir)
 temp$n - 50
 assign(stateA, value=temp, envir=envir)

 return(TRUE)
}

fight2(stateA=state1, stateB=state2, envir=env)

# Extract from environment
state1 - env$state1
state1
state2 - env$state2
state2

2) Using Reference Classes

# Class Def
setRefClass(State,
 fields=list(n=numeric, won=numeric),
 methods=list(
 fight2=function(...){
 fight2Ref(.self=.self, ...)
 }
 )
)
# Set Generic
setGeneric(name=fight2Ref, signature=.self, def=function(.self, ...)
 standardGeneric(fight2Ref))
# Set Method
setMethod(f=fight2Ref, signature=State,
 definition=function(
 .self,
 value,
 ...
 ){
 .self$n - value
 }
)
# Note:
# You could also put the code inside 'fight2Ref' directly inside the 
class def,
# but I don't want them to be too crowded, so I go by 'divide and conquer'

# Instantiate objects
state1 - new(State, n=100, won=0)
state1
state2 - new(State, n=100, won=0)
state2

# Apply method
state1$fight2(value=50)
state1
state2$fight2(value=50)
state2

# Back to list
stateToList - function(obj, ...){
 fields - names(getRefClass(State)$fields())
 out - lapply(fields, function(x.field){
 obj$field(x.field)
 })
 names(out) - fields
 return(out)
}
state1 - stateToList(state1)
state1
state2 - stateToList(state2)
state2

HTH,
Janko

On 06.12.2011 22:06, R. Michael Weylandt wrote:
 No pointer functionality in R (that I know of), but if you want to
 return two objects as one the standard way is to put them in a list
 and to return that list.

 Michael

 On Tue, Dec 6, 2011 at 2:35 PM, Yevkirp...@gmail.com  wrote:
 I'm trying to write a function that takes several objects with many
 different attributes and then changes their attributes. So what I wanted to
 happen in the simplified example below is for the function to change the
 attributes of the objects state1 and state2 that are passed to it. But
 because stateA and stateB are local, this isn't working. Are there any easy
 solutions?

 e.g., if I could combine the two objects stateA and stateB into a single
 object, I could return it and then assign it back to objects state1 and
 state2. Or if I could pass a pointer to the original object.. But I cannot
 find an easy way of doing either.  Thanks in advance..

 state1- list(n=100, won=0)
 state2- list(n=100, won=0)

 fight2- function(stateA, stateB){
stateA$n- 50
stateB$n-50
 }

 fight2(state1,state2)

 state1$n
 state2$n

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org  mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 __
 R-help@r-project.org  mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 


*Janko Thyson*
janko.thy...@ku-eichstaett.de mailto:janko.thy...@ku-eichstaett.de

Catholic University of Eichstätt-Ingolstadt
Ingolstadt School of Management
Statistics and Quantitative Methods
Auf der Schanz 49
D-85049 Ingolstadt

www.wfi.edu/lsqm http://www.wfi.edu/lsqm

Fon: +49 841 937-1923
Fax: +49 841 937-1965

This e-mail and any attachment is for authorized use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by any other party.
If you are not an intended recipient then please promptly delete this
e-mail and any attachment and all copies and inform the sender.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] nice report generator?

2011-12-07 Thread Janko Thyson
I like knitr. IMHO Yihui really came up with a killer package there: 
http://yihui.github.com/knitr/


On 07.12.2011 19:19, Sarah Goslee wrote:

Sweave.

Or ODFWeave, if Sweave/LaTeX are too much overhead.

But really, it depends on what kind of report output you need to
deliver. Printed? HTML? PDF?

Sarah

On Wed, Dec 7, 2011 at 1:14 PM, Michaelcomtech@gmail.com  wrote:

Hi all,

I am looking for recommendations/pointers about best report generator you
think that are currently available?

i.e. the package that can help turn console output into nice-looking neat
report to send to bosses?

thanks a lot!
.





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to write (complex) coercion methods or what's the reason to limit 'setAs()' the way it is limited?

2011-12-04 Thread Janko Thyson

Dear list,

I'd like to write coercion methods for some of my Reference Classes. 
However, using 'setAs()' is not a real option as its argument 'def' only 
allows for functions depending on one single argument. In some cases, 
that is simply too much of a limitation for me. And I don't really see 
why it needs to be this way, so I guess this question is also some sort 
of a feature request to make 'setAs' a bit more flexible (in case anyone 
from the Core Team is listening ;-))


A reproducible example can be found here: 
http://stackoverflow.com/questions/8346654/how-to-write-coercion-methods


Thanks a lot for any replies!
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Why does loading saved/cached objects add significantly to RAM consumption?

2011-09-01 Thread Janko Thyson

On 30.08.2011 20:33, Henrik Bengtsson wrote:

Hi.

On Tue, Aug 30, 2011 at 3:59 AM, Janko Thyson
janko.thyson.rst...@googlemail.com  wrote:

Dear list,

I make use of cached objects extensively for time consuming computations and
yesterday I happened to notice some very strange behavior in that respect:
When I execute a given computation whose result I'd like to cache (tried
both saving it as '.Rdata' and via package 'R.cache' which uses a own
filetype '.Rcache'),

Just to clarify, it is just the filename extension that is custom;
it uses base::save() internally.  It is very unlikely that R.cache has
to do with your problem.


Okay, got it.




my R session consumes about 200 MB of RAM, which is
fine. Now, when I make use of the previously cached object (i.e. loading it,
assigning it to a certain field of a Reference Class object), I noticed that
RAM consumption of my R process jumps to about 250 MB!
a
Each new loading of cached/saved objects adds to that consumption (in total,
I have about 5-8 objects that are processed this way), so at some point I
easily get a RAM consumption of over 2 GB where I'm only at about 200 MB of
consumption when I compute each object directly! Object sizes (checked with
'object.size()') remain fairly constant. What's even stranger: after loading
cached objects and removing them (either via 'rm()' or by assigning a
'fresh' empty object to the respective Reference Class field, RAM
consumption remains at this high level and never comes down again.

I checked the behavior also in a small example which is a simplification of
my use case and which you'll find below (checked both on Win XP and Win 7 32
bit). I couldn't quite reproduce an immediate increase in RAM consumption,

I couldn't reproduce it either using sessionInfo():

R version 2.13.1 Patched (2011-08-29 r56823)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
loaded via a namespace (and not attached):
[1] tools_2.13.1


I'll try to come up with an example that resembles more of my actual use 
case.



but what I still find really strange is
a) why do repeated 'load()' calls result in an increase in RAM consumption?
b) why does the latter not go down again after the objects have been removed
from '.GlobalEnv'?


Thanks for the hint to an explicit call to 'gc()'. That brings down 
memorey usage and would work if I wouldn't need the content of the 
objects I load and could therefore remove them ('rm(x)'; 'gc()'), but 
that's exactly what I need: load data and assign it to some environments.



Removed objects may still sit in memory - it is only when R's garbage
collector (GC) comes around and removes them that the memory usage
goes down.  You can force the garbage collector to run by calling
gc(), but normally it is automatically triggered whenever needed.

Note that the GC will only be able to clean up the memory of removed
objects IFF there are no other references to that object/piece of
memory.  When you use References classes (cf. setRefClass()) and
environments, you end up keeping references internally in objects
without being aware of it.  My guess is that your other code may have
such issues, whereas the code below does not.

There is also the concept of promises [see 'R Language Definition'
document], which *may* also be involved.

FYI, the Sysinternals Process Explorer
[http://technet.microsoft.com/en-us/sysinternals/bb896653] is a useful
tool for studying individual processes such as R.


Thanks for that one as well! I'll have a more detailed look into this.

Best regards,
Janko


My $.02

Henrik


Did anyone of you experience a similar behavior? Or even better, does anyone
know why this is happening and how it might be fixed (or be worked around)?
;-)

I really need your help on this one as it's crucial for my thesis, thanks a
lot for anyone replying!!

Regards,
Janko

# EXAMPLE #

setRefClass(A, fields=list(.PRIMARY=environment))
setRefClass(Test, fields=list(a=A))

obj.1- lapply(1:5000, function(x){
rnorm(x)
})
names(obj.1)- paste(sample, 1:5000, sep=.)
obj.1- as.environment(obj.1)

test- new(Test, a=new(A, .PRIMARY=obj.1))
test$a$.PRIMARY$sample.10

#+

object.size(test)
object.size(test$a)
object.size(obj.1)
# RAM used by R session: 118 MB

save(obj.1, file=C:/obj.1.Rdata)
# Results in an object of ca. 94 MB
save(test, file=C:/test.Rdata)
# Results in an object of ca. 94 MB

# START A NEW R SESSION #

load(C:/test.Rdata)
# RAM consumption still fine at 115 - 118 MB

# But watch how it goes up as we repeatedly load objects
for(x in 1:5){
load(C:/test.Rdata)
}
for(x in 1:5){
load(C:/obj.1.Rdata)
}
# Somehow there seems to be an upper limit, though

# Removing the objects does not bring down RAM consumption
rm

[R] Why does loading saved/cached objects add significantly to RAM consumption?

2011-08-30 Thread Janko Thyson

Dear list,

I make use of cached objects extensively for time consuming computations 
and yesterday I happened to notice some very strange behavior in that 
respect:
When I execute a given computation whose result I'd like to cache (tried 
both saving it as '.Rdata' and via package 'R.cache' which uses a own 
filetype '.Rcache'), my R session consumes about 200 MB of RAM, which is 
fine. Now, when I make use of the previously cached object (i.e. loading 
it, assigning it to a certain field of a Reference Class object), I 
noticed that RAM consumption of my R process jumps to about 250 MB!

a
Each new loading of cached/saved objects adds to that consumption (in 
total, I have about 5-8 objects that are processed this way), so at some 
point I easily get a RAM consumption of over 2 GB where I'm only at 
about 200 MB of consumption when I compute each object directly! Object 
sizes (checked with 'object.size()') remain fairly constant. What's even 
stranger: after loading cached objects and removing them (either via 
'rm()' or by assigning a 'fresh' empty object to the respective 
Reference Class field, RAM consumption remains at this high level and 
never comes down again.


I checked the behavior also in a small example which is a simplification 
of my use case and which you'll find below (checked both on Win XP and 
Win 7 32 bit). I couldn't quite reproduce an immediate increase in RAM 
consumption, but what I still find really strange is

a) why do repeated 'load()' calls result in an increase in RAM consumption?
b) why does the latter not go down again after the objects have been 
removed from '.GlobalEnv'?


Did anyone of you experience a similar behavior? Or even better, does 
anyone know why this is happening and how it might be fixed (or be 
worked around)? ;-)


I really need your help on this one as it's crucial for my thesis, 
thanks a lot for anyone replying!!


Regards,
Janko

# EXAMPLE #

setRefClass(A, fields=list(.PRIMARY=environment))
setRefClass(Test, fields=list(a=A))

obj.1 - lapply(1:5000, function(x){
rnorm(x)
})
names(obj.1) - paste(sample, 1:5000, sep=.)
obj.1 - as.environment(obj.1)

test - new(Test, a=new(A, .PRIMARY=obj.1))
test$a$.PRIMARY$sample.10

#+

object.size(test)
object.size(test$a)
object.size(obj.1)
# RAM used by R session: 118 MB

save(obj.1, file=C:/obj.1.Rdata)
# Results in an object of ca. 94 MB
save(test, file=C:/test.Rdata)
# Results in an object of ca. 94 MB

# START A NEW R SESSION #

load(C:/test.Rdata)
# RAM consumption still fine at 115 - 118 MB

# But watch how it goes up as we repeatedly load objects
for(x in 1:5){
load(C:/test.Rdata)
}
for(x in 1:5){
load(C:/obj.1.Rdata)
}
# Somehow there seems to be an upper limit, though

# Removing the objects does not bring down RAM consumption
rm(obj.1)
rm(test)

##

 Sys.info()
 sysname  release
   Windows XP
 version nodename
build 2600, Service Pack 3   ASHB-109C-02
 machinelogin
   x86 wwa418
user
wwa418

 sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

loaded via a namespace (and not attached):
[1] codetools_0.2-8 tools_2.13.1

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] string manipulation

2011-08-26 Thread Janko Thyson

You might want to take a look at 'regexpr' and/or 'gregexpr':

mytext - I want the number 2000, not the number two thousand
idx - regexpr(\\d{4}, mytext)
idx - c(idx, (idx + attributes(idx)$match.length)-1)
substr(start=idx[1], stop=idx[2], mytext)

HTH,
Janko

On 26.08.2011 03:51, Lorenzo Cattarino wrote:

Apologies for confusion. What I meant was the following:

mytext- I want the number 2000, not the number two thousand

and the problem is to select 2000 as the first four digits after the word 
number. The position of 2000 in the string might change.

thanks
Lorenzo

-Original Message-
From: Steven Kennedy [mailto:stevenkennedy2...@gmail.com]
Sent: Friday, 26 August 2011 11:31 AM
To: Henrique Dallazuanna
Cc: Lorenzo Cattarino; r-help@r-project.org
Subject: Re: [R] string manipulation

You can split your string, and then only take the first 4 digits after
that (this is only an improvement if your numbers might not be at the
end of mytext):

mytext- I do not want the first number 1234, but the second number 5678
sstr-strsplit(mytext,split=second number )[[1]][2]
nynumbers-substr(sstr,1,4)


On Fri, Aug 26, 2011 at 11:18 AM, Henrique Dallazuannawww...@gmail.com  wrote:

Try this:

gsub(.*second number , , mytext)

On Thu, Aug 25, 2011 at 8:00 PM, Lorenzo Cattarino
l.cattar...@uq.edu.au  wrote:

I R-users,

I am trying to find the way to manipulate a character string to select a 4 
digit number after some specific word/s. Example:

mytext- I do not want the first number 1234, but the second number 5678

Is there any function that allows you to select a certain number of digits (in 
this case 5678) after a particular word/s (e.g., second number)

Thank you for your help

Lorenzo


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Simple inheritance check fails (integer from numeric)

2011-07-07 Thread Janko Thyson

Dear list,

In a function, I don't care if my input has class 'integer' or 
'numeric', so I wanted to use 'inherits()' to control for that.


However, this function tells me that an actual object of class 'integer' 
does not inherit from class 'numeric'. The class def of 'integer' does 
state 'numeric' as one of the superclasses. Isn't that somewhat 
inconsistent?


 getClass(integer)
Class integer [package methods]

No Slots, prototype of class integer

Extends: numeric, vector, data.frameRowLabels

 a - 1:3
 class(a)
[1] integer

 inherits(a, numeric)
[1] FALSE

Regards,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Simple inheritance check fails (integer from numeric)

2011-07-07 Thread Janko Thyson

On 07.07.2011 16:09, David Winsemius wrote:


On Jul 7, 2011, at 6:01 AM, Janko Thyson wrote:


Dear list,

In a function, I don't care if my input has class 'integer' or 
'numeric', so I wanted to use 'inherits()' to control for that.


However, this function tells me that an actual object of class 
'integer' does not inherit from class 'numeric'. The class def of 
'integer' does state 'numeric' as one of the superclasses. Isn't that 
somewhat inconsistent?


 getClass(integer)
Class integer [package methods]

No Slots, prototype of class integer

Extends: numeric, vector, data.frameRowLabels

 a - 1:3
 class(a)
[1] integer

 inherits(a, numeric)
[1] FALSE



 a - 1:3
 is.numeric(a)
[1] TRUE
;-) Sure, but for me that doesn't explain why 'inherits()' won't 
recognize the inheritance. And it's not generic enough for the methods 
I'd like to write.


I'd like to check if, say, 'src' inherits from 'tgt' which would 
specifies an arbitrary class. And I would like to get around testing all 
sorts of combinations like if  'tgt' specifies class 'numeric', then 
try 'is.numeric(src)':


simpleFoo - function(src, tgt){
if(inherits(src, tgt)){
print(yep)
} else {
print(nope)
}
}
x - 1:3
class(x) - c(class(x), AAA)
simpleFoo(src=x, tgt=AAA)

x - 1:3
simpleFoo(src=x, tgt=numeric)

But thanks for the answer!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Update MS Windows PATH variable based on a R script

2011-06-30 Thread Janko Thyson

On 29.06.2011 21:24, Duncan Murdoch wrote:

On 29/06/2011 3:15 PM, Janko Thyson wrote:

On 29.06.2011 20:58, Duncan Murdoch wrote:

On 29/06/2011 2:24 PM, Janko Thyson wrote:

Dear list,

this is not directly an R question, but it is somewhat related to R
aspects, so I hope it's okay to post it here:

I'd like to update my windows PATH based on a script routine in 
order to
make sure that crucial components are contained. Much like what 
happens

at the installation of Rtools (if desired). Now, can you do that from
within R or do I need some sort of windows batch file or something 
like

AutoIt script (http://www.autoitscript.com/site/autoit/)? If so, what
would I need to put in there?


You need to set the registry entry if you want a persistent change to
the PATH.  Sys.setenv just modifies R's copy of the PATH.  Child
processes will see the modifications, but they don't last beyond the R
session.

You'll have to check MS docs to find which registry entry to mess
with.  Alternatively, if you feel lucky, just use Control Panel to set
some strange path, then see where your change showed up using regedit.

R doesn't have a built-in function to write to the registry, but there
are various utilities available outside of R to do it.

Duncan Murdoch


Thanks for the quick answer!
Would you mind sharing how you do it with the Rtools Windows installer?
Or is that too much bound to installer details and can't be secluded
very well?


We use the Inno Setup installer; it has a function for this.  Here's 
the code used:


Root: HKLM; Subkey: SYSTEM\CurrentControlSet\Control\Session 
Manager\Environment; ValueType: expandsz; ValueName: PATH; ValueData: 
{code:getNewPath}; Tasks: setPath


So I guess I do know what the registry key is.


Great, thanks a lot!





The motivation behind this is that I came to love applications that can
be run portably (i.e. apps that don't write anything to the Windows
registry and can therefore be easily be installed on a USB drive, for
example). That works just fine with R, my IDE Eclipse and also Rtools.
The problem is that I need a batch script that optionally checks under
which letter my USB drive is mounted and updates the relevant paths to
Rtools binaries in my Windows PATH to make it somewhat dynamical. Of
course I'd like to clean everything up once my R-session terminates so I
can reset the Windows PATH to it's original state once I'm finished
working at a specific PC.

What I also just thought of: is there some way to specify relative and
not absolute paths in the windows PATH? I know that this works when you
have an .exe as a reference point (e.g. '..\somedir\' goes up one
directory relative to the directory where the .exe is called and then
moves into 'somedir'). But since there is no such thing as an .exe
involved, there's probably no way to do it.


As far as I know that's fine with R.  It uses various .exe's in the 
bin/i386 or bin/x64 directories.  It doesn't use the path for anything 
beyond startup.


Duncan Murdoch



But thanks for the info, I'll have a look at MS specific documentation
to get the job done.

Regards,
Janko




Here's what I tried in R:

unlist(strsplit(Sys.getenv(PATH), ;))
PATH.0- Sys.getenv(PATH)
PATH.1- paste(PATH.0, C:\\blabla\bin)
Sys.setenv(PATH=PATH.1)
unlist(strsplit(Sys.getenv(PATH), ;))

The changes seem to be reflected, but when I check my PATH the new 
entry

isn't there. I guess there is no actual feedback to Windows system
environment variable and that's exactly what I would like to 
accomplish


Thanks a lot for any advice,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.










__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Update MS Windows PATH variable based on a R script

2011-06-29 Thread Janko Thyson

Dear list,

this is not directly an R question, but it is somewhat related to R 
aspects, so I hope it's okay to post it here:


I'd like to update my windows PATH based on a script routine in order to 
make sure that crucial components are contained. Much like what happens 
at the installation of Rtools (if desired). Now, can you do that from 
within R or do I need some sort of windows batch file or something like 
AutoIt script (http://www.autoitscript.com/site/autoit/)? If so, what 
would I need to put in there?


Here's what I tried in R:

unlist(strsplit(Sys.getenv(PATH), ;))
PATH.0 - Sys.getenv(PATH)
PATH.1 - paste(PATH.0, C:\\blabla\bin)
Sys.setenv(PATH=PATH.1)
unlist(strsplit(Sys.getenv(PATH), ;))

The changes seem to be reflected, but when I check my PATH the new entry 
isn't there. I guess there is no actual feedback to Windows system 
environment variable and that's exactly what I would like to accomplish


Thanks a lot for any advice,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Update MS Windows PATH variable based on a R script

2011-06-29 Thread Janko Thyson

On 29.06.2011 20:58, Duncan Murdoch wrote:

On 29/06/2011 2:24 PM, Janko Thyson wrote:

Dear list,

this is not directly an R question, but it is somewhat related to R
aspects, so I hope it's okay to post it here:

I'd like to update my windows PATH based on a script routine in order to
make sure that crucial components are contained. Much like what happens
at the installation of Rtools (if desired). Now, can you do that from
within R or do I need some sort of windows batch file or something like
AutoIt script (http://www.autoitscript.com/site/autoit/)? If so, what
would I need to put in there?


You need to set the registry entry if you want a persistent change to 
the PATH.  Sys.setenv just modifies R's copy of the PATH.  Child 
processes will see the modifications, but they don't last beyond the R 
session.


You'll have to check MS docs to find which registry entry to mess 
with.  Alternatively, if you feel lucky, just use Control Panel to set 
some strange path, then see where your change showed up using regedit.


R doesn't have a built-in function to write to the registry, but there 
are various utilities available outside of R to do it.


Duncan Murdoch


Thanks for the quick answer!
Would you mind sharing how you do it with the Rtools Windows installer? 
Or is that too much bound to installer details and can't be secluded 
very well?


The motivation behind this is that I came to love applications that can 
be run portably (i.e. apps that don't write anything to the Windows 
registry and can therefore be easily be installed on a USB drive, for 
example). That works just fine with R, my IDE Eclipse and also Rtools. 
The problem is that I need a batch script that optionally checks under 
which letter my USB drive is mounted and updates the relevant paths to 
Rtools binaries in my Windows PATH to make it somewhat dynamical. Of 
course I'd like to clean everything up once my R-session terminates so I 
can reset the Windows PATH to it's original state once I'm finished 
working at a specific PC.


What I also just thought of: is there some way to specify relative and 
not absolute paths in the windows PATH? I know that this works when you 
have an .exe as a reference point (e.g. '..\somedir\' goes up one 
directory relative to the directory where the .exe is called and then 
moves into 'somedir'). But since there is no such thing as an .exe 
involved, there's probably no way to do it.


But thanks for the info, I'll have a look at MS specific documentation 
to get the job done.


Regards,
Janko




Here's what I tried in R:

unlist(strsplit(Sys.getenv(PATH), ;))
PATH.0- Sys.getenv(PATH)
PATH.1- paste(PATH.0, C:\\blabla\bin)
Sys.setenv(PATH=PATH.1)
unlist(strsplit(Sys.getenv(PATH), ;))

The changes seem to be reflected, but when I check my PATH the new entry
isn't there. I guess there is no actual feedback to Windows system
environment variable and that's exactly what I would like to accomplish

Thanks a lot for any advice,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Reset R's library to base packages only (remove all installed contributed packages)

2011-06-14 Thread Janko Thyson

Dear list,

is there a way to comfortably reset R's library such that it only 
contains only the base packages again? In other words, how can I 
uninstall all contributed packages that I installed? Is there some sort 
of index that's keeping track of what has been installed? If so, a 
pointer would be great.


AFAIU, if you don't create such an index file yourself and loose track 
of what you installed, probably the best way to reset R is to actually 
re-install it. That's exactly what I'm trying to avoid.


I would like something like

path.lib - path/to/R/lib
pkgs.to.remove - readLines(path.to.index.file)
sapply(pkgs.to.remove, uninstall.packages, lib=path.lib)

Best regards,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reset R's library to base packages only (remove all installed contributed packages)

2011-06-14 Thread Janko Thyson

On 14.06.2011 13:34, Uwe Ligges wrote:



On 14.06.2011 12:04, Janko Thyson wrote:

Dear list,

is there a way to comfortably reset R's library such that it only
contains only the base packages again? In other words, how can I
uninstall all contributed packages that I installed? Is there some sort
of index that's keeping track of what has been installed? If so, a
pointer would be great.

AFAIU, if you don't create such an index file yourself and loose track
of what you installed, probably the best way to reset R is to actually
re-install it. That's exactly what I'm trying to avoid.

I would like something like

path.lib - path/to/R/lib
pkgs.to.remove - readLines(path.to.index.file)


ip - installed.packages()
pkgs.to.remove - ip[!(ip[,Priority] %in% c(base, recommended)), 1]

This way you select all installed packages that do not ship with R (as 
base or recommended ones).


Uwe Ligges



Great, thanks!





sapply(pkgs.to.remove, uninstall.packages, lib=path.lib)

Best regards,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How can I write methods for 'as()'?

2011-06-06 Thread Janko Thyson
Dear list,

I wonder how to write methods for the function 'as' in the sense that I 
can call 'as(object, Class, strict=TRUE, ext)' and let method dispatch 
figure out the correct method.

AFAIU, there is a difference between, e.g. 'as.data.frame' and the 
methods of 'as()' as stated above since the former depends on arg 'x' 
instead of 'object', 'Class' etc.?

  methods(as)
  as.data.frame

I have to admit that I'm not really familiar with the S3 style of 
defining methods as I have been coding in S4 a lot, but my first attempt 
was to write something like this:

as.myClass - function(x, ...){
 if(is(x, data.frame){
 x - as.list(x)
 }
 if(is(x, character){
 x - as.list(x)
 }
 ...
 out - getRefClass(myClass)$new(X=x)
 return(out)
}

But that way I'd have to explicitly call 'as.myClass(x)' whereas I'd 
simply like to type 'as(x, myClass)'.
Also, how is it possible to have method dispatch recognize two  
signature arguments in S3? I.e., how can I define something like 
'as.data.frame.character' in order to have explicit sub methods for 
all the data types of 'x' so I wouldn't have to process them all in the 
definition of 'as.myClass' as I did above?

Thanks for your help,
Janko


-- 


*Janko Thyson*
janko.thy...@googlemail.com mailto:janko.thy...@googlemail.com

Jesuitenstraße 3
D-85049 Ingolstadt

Mobile: +49 (0)176 83294257

This e-mail and any attachment is for authorized use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by any other party.
If you are not an intended recipient then please promptly delete this
e-mail and any attachment and all copies and inform the sender.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How can I write methods for 'as()'?

2011-06-06 Thread Janko Thyson
Somehow I don't see my own postings in the list, so sorry for replying 
to my own message and not the one that went out to the list.

I got a little further and I think I found exactly the thing that is 
bothering me: how to get extended method dispatch going in 'setAs()':

setRefClass(A, fields=list(X=numeric))
setRefClass(B, contains=A, fields=list(Y=character))

setAs(from=numeric, to=A,
 def=function(from,to){
 out - getRefClass(to)$new(X=from)
 return(out)
 }
)
a - as(1:5, A)
a$X

b - as(1:5, B)

My problem is the last statement (b - as(1:5, B) which fails. I want 
to get around having to write new 'setAs' methods for all classes 
extending class 'A'. If 'B' inherits from 'A', shouldn't it then be 
possible to tell 'setAs' to look for the next suitable method, i.e. the 
method defined for 'A'? I tried 'NextMethod()' inside the body of 
'setAs' but that didn't work out.

Thanks a lot,
Janko

On 06.06.2011 17:15, Janko Thyson wrote:
 Dear list,

 I wonder how to write methods for the function 'as' in the sense that 
 I can call 'as(object, Class, strict=TRUE, ext)' and let method 
 dispatch figure out the correct method.

 AFAIU, there is a difference between, e.g. 'as.data.frame' and the 
 methods of 'as()' as stated above since the former depends on arg 'x' 
 instead of 'object', 'Class' etc.?

  methods(as)
  as.data.frame

 I have to admit that I'm not really familiar with the S3 style of 
 defining methods as I have been coding in S4 a lot, but my first 
 attempt was to write something like this:

 as.myClass - function(x, ...){
 if(is(x, data.frame){
 x - as.list(x)
 }
 if(is(x, character){
 x - as.list(x)
 }
 ...
 out - getRefClass(myClass)$new(X=x)
 return(out)
 }

 But that way I'd have to explicitly call 'as.myClass(x)' whereas I'd 
 simply like to type 'as(x, myClass)'.
 Also, how is it possible to have method dispatch recognize two  
 signature arguments in S3? I.e., how can I define something like 
 'as.data.frame.character' in order to have explicit sub methods for 
 all the data types of 'x' so I wouldn't have to process them all in 
 the definition of 'as.myClass' as I did above?

 Thanks for your help,
 Janko

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How can I write methods for 'as()'?

2011-06-06 Thread Janko Thyson
Okay, I found something that is working, but it looks and feels pretty 
awkward as the method def and method lookup takes place in one function ;-)

setRefClass(A, fields=list(X=numeric))
setRefClass(B, contains=A, fields=list(Y=character))

mySetAs - function(
 from,
 to
){
 if(!existsMethod(f=coerce, signature=c(from=class(from), to=to))){
 setAs(from=class(from), to=to,
 def=function(from, to){
 out - getRefClass(to)$new(X=from)
 return(out)
 }
 )
 }
 mthd - selectMethod(coerce, signature=c(from=class(from), 
to=to), useInherited= c(from=TRUE, to=TRUE))
 out - mthd(from=from, to=to)
 return(out)
}

a - mySetAs(from=1:5, to=A)
a$X
b - mySetAs(from=1:5, to=B)
b$X

I'm sure there are much better ways. I'd appreciate any comments whatsoever.

Best regards,
Janko

On 06.06.2011 17:46, Janko Thyson wrote:
 Somehow I don't see my own postings in the list, so sorry for replying 
 to my own message and not the one that went out to the list.

 I got a little further and I think I found exactly the thing that is 
 bothering me: how to get extended method dispatch going in 'setAs()':

 setRefClass(A, fields=list(X=numeric))
 setRefClass(B, contains=A, fields=list(Y=character))

 setAs(from=numeric, to=A,
 def=function(from,to){
 out - getRefClass(to)$new(X=from)
 return(out)
 }
 )
 a - as(1:5, A)
 a$X

 b - as(1:5, B)

 My problem is the last statement (b - as(1:5, B) which fails. I 
 want to get around having to write new 'setAs' methods for all classes 
 extending class 'A'. If 'B' inherits from 'A', shouldn't it then be 
 possible to tell 'setAs' to look for the next suitable method, i.e. 
 the method defined for 'A'? I tried 'NextMethod()' inside the body of 
 'setAs' but that didn't work out.

 Thanks a lot,
 Janko

 On 06.06.2011 17:15, Janko Thyson wrote:
 Dear list,

 I wonder how to write methods for the function 'as' in the sense that 
 I can call 'as(object, Class, strict=TRUE, ext)' and let method 
 dispatch figure out the correct method.

 AFAIU, there is a difference between, e.g. 'as.data.frame' and the 
 methods of 'as()' as stated above since the former depends on arg 'x' 
 instead of 'object', 'Class' etc.?

  methods(as)
  as.data.frame

 I have to admit that I'm not really familiar with the S3 style of 
 defining methods as I have been coding in S4 a lot, but my first 
 attempt was to write something like this:

 as.myClass - function(x, ...){
 if(is(x, data.frame){
 x - as.list(x)
 }
 if(is(x, character){
 x - as.list(x)
 }
 ...
 out - getRefClass(myClass)$new(X=x)
 return(out)
 }

 But that way I'd have to explicitly call 'as.myClass(x)' whereas I'd 
 simply like to type 'as(x, myClass)'.
 Also, how is it possible to have method dispatch recognize two  
 signature arguments in S3? I.e., how can I define something like 
 'as.data.frame.character' in order to have explicit sub methods for 
 all the data types of 'x' so I wouldn't have to process them all in 
 the definition of 'as.myClass' as I did above?

 Thanks for your help,
 Janko

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there a (virtual) class that all R objects inherit from?

2011-06-03 Thread Janko Thyson
On 31.05.2011 18:17, Martin Morgan wrote:
 On 05/30/2011 07:02 AM, Janko Thyson wrote:
 Dear list,

 I would like to set one specific Reference Class field to be of an
 arbitrary class. Is there a class that all R objects inherit from? I
 thought that ANY was something like this, but obviously that's not 
 true:

   inherits(1:3, ANY)
 [1] FALSE

 I can't speak to the implementation, but ANY functions as a base class 
 in terms of slot / field assignment and inheritance, e.g.,

   setClass(A, representation(x=ANY))
   new(A, x=1:3)

 Martin

Hi Martin,

sorry for the late response. The way you do it works. Yet, when you 
declare dependencies more explicitly (contains=XY), then R complains. Is 
this a feature or a bug (with respect to the less explicit way working 
just fine)? See the example below:

# S4
setClass(A, representation(x=ANY))
new(A, x=1:3)

setClass(A, representation(x=ANY))
setClass(B, contains=A, representation(x=character))
new(B, x=1:3)

# Reference Classes
setRefClass(
 Class=A,
 fields=list(
 .PRIMARYDATA=ANY
 ),
 contains=c(VIRTUAL)
)
B - setRefClass(
 Class=B,
 fields=list(
 .PRIMARYDATA=character
 ),
 contains=c(A)
)

Regards,
Janko

 Regards,
 Janko

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 


*Janko Thyson*
janko.thy...@googlemail.com mailto:janko.thy...@googlemail.com

Jesuitenstraße 3
D-85049 Ingolstadt

Mobile: +49 (0)176 83294257

This e-mail and any attachment is for authorized use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by any other party.
If you are not an intended recipient then please promptly delete this
e-mail and any attachment and all copies and inform the sender.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Is there a (virtual) class that all R objects inherit from?

2011-05-30 Thread Janko Thyson
Dear list,

I would like to set one specific Reference Class field to be of an 
arbitrary class. Is there a class that all R objects inherit from? I 
thought that ANY was something like this, but obviously that's not true:

  inherits(1:3, ANY)
[1] FALSE

Regards,
Janko

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Remove duplicate elements in lists via recursive indexing

2011-05-23 Thread Janko Thyson

Dear list,

I'm trying to solve something pretty basic here, but I can't really come 
up with a good solution. Basically, I would just like to remove 
duplicated named elements in lists via a their respective recursive 
indexes (given that I have a routine that identifies these recursive 
indexes). Here's a little example:


# VECTORS
# Here, it's pretty simple to remove duplicated entries
y - c(1,2,3,1,1)
idx.dupl - which(duplicated(y))
y - y[-idx.dupl]
# /

# LISTS
x - list(a=list(a.1.1=1, a.1.1=2, a.1.1=3))

x[[c(1,1)]]
x[[c(1,2)]] # Should be removed.
x[[c(1,3)]] # Should be removed.

# Let's say a 'checkDuplicates' routine would give me:
idx.dupl - list(c(1,2), c(1,3))

# Remove first duplicate:
x[[idx.dupl[[1 - NULL
x
# Problem:
# Once I remove the first duplicate, my duplicate index would have to be
# updated as well as there is not third element anymore.
x[[idx.dupl[[2 - NULL

# So something like this would not work:
sapply(idx.dupl, function(x.idx){
x[[x.idx]] - NULL
})
# /

Sorry if I'm missing something totally obvious here, but do you have any 
idea how to solve this?


Thanks a lot,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Remove duplicate elements in lists via recursive indexing

2011-05-23 Thread Janko Thyson

Hi Timothy,

and thanks for the answer. Loops where exactly what I was trying to 
avoid as much as possible. My initial idea was that that once I had 
recursive indexes at my disposal (which were retrieved over recursive 
loops),  I could simply use it in a similar manner as we do with indexes 
(that is 'do-all-at-once', like in 'x - x[-idx.drop]'). But I think 
even though recursive indexes are nice, you can't get around looping, 
which I think in turn means that you constantly have to adapt your 
recursive index set to the most recent 'state' of your list.


In case you're interested, in the attachment you'll find my current 
solution ('listDuplicatesProcess.txt' including the example script 
'listDuplicatesProcess_examples.txt'). It builds on some other code, so 
you'd have to source 'flatten.txt' and 'envirToList' as well.


Regards,
Janko

On 23.05.2011 14:23, Timothy Bates wrote:

Dear Janko,
I think requires a for loop. The approach I took here was mark the dups, then 
dump them all in one hit:

testData = expand.grid(letters[1:4],c(1:3))
testData$keep=F
uniqueIDS = unique(testData$Var1)
for(thisID in uniqueIDS) {
firstCaseOnly = match(thisID,testData$Var1)
testData[firstCaseOnly,keep]=T
}

(testData = testData[testData$keep==T,])


On 23 May 2011, at 11:59 AM, Janko Thyson wrote:


Dear list,

I'm trying to solve something pretty basic here, but I can't really come up 
with a good solution. Basically, I would just like to remove duplicated named 
elements in lists via a their respective recursive indexes (given that I have a 
routine that identifies these recursive indexes). Here's a little example:

# VECTORS
# Here, it's pretty simple to remove duplicated entries
y- c(1,2,3,1,1)
idx.dupl- which(duplicated(y))
y- y[-idx.dupl]
# /

# LISTS
x- list(a=list(a.1.1=1, a.1.1=2, a.1.1=3))

x[[c(1,1)]]
x[[c(1,2)]] # Should be removed.
x[[c(1,3)]] # Should be removed.

# Let's say a 'checkDuplicates' routine would give me:
idx.dupl- list(c(1,2), c(1,3))

# Remove first duplicate:
x[[idx.dupl[[1- NULL
x
# Problem:
# Once I remove the first duplicate, my duplicate index would have to be
# updated as well as there is not third element anymore.
x[[idx.dupl[[2- NULL

# So something like this would not work:
sapply(idx.dupl, function(x.idx){
x[[x.idx]]- NULL
})
# /

Sorry if I'm missing something totally obvious here, but do you have any idea 
how to solve this?

Thanks a lot,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

#' Coerce Environment to List (Recursively).
#'
#' Recursively coerces an \code{environment} to a \code{list}.  
#'
#' @param src A an \code{environment} that should be coerced.
#' @param order.type A \code{character} vector (length: max=1) specifying if
#' the list elements should be ordered and if so, what type of ordering should
#' be applied.
#' @param ... Further args.
#' @return A named \code{list} that corresponds to the recursively coerced
#' initial \code{environment}.
#' @callGraphPrimitives
#' @author Janko Thyson \email{janko.thyson.rstuff@@googlemail.com}
#' @seealso \code{\link{flatten}}
#' @example inst/examples/envirAsList.R
envirToList - function(
src, 
order.type=c(increasing, decreasing, none),
...
){
if(length(order.type)  1){
order.type - order.type[1]
}
if(class(src) == environment){
envir   - new.env()  
src - as.list(src)
# LOOP OVER ELEMENTS
out - lapply(seq(along=src), function(x.src){
envir$names - c(envir$names, names(src[x.src]))
# RECURSIVE FLATTENING
out - envirToList(src[[x.src]])
return(out)
})
names(out) - envir$names
if(order.type == increasing){
idx.order - order(names(out))
out - out[idx.order]
}
if(order.type == decreasing){
idx.order - order(names(out), decreasing=TRUE)
out - out[idx.order]
}
# /
} else {
out - src 
}
return(out)
}#' Flatten (Nested) Lists or Environments.
#'
#' Flatten \code{lists} or \code{environments} according to specifications
#' made via arg \code{start.after} and/or arg \code{stop.at}. When keeping 
#' the defaults, the function will traverse arg \code{src} (if \code{src} is 
#' an \code{environment}, it is coerced to a \code{list} 
#' via \code{\link{envirToList}} first) to retrieve the values at the 
#' respective bottom layers/bottom elements. These values are arranged

Re: [R] Passing function arguments to dataset names

2011-05-23 Thread Janko Thyson
Hi Mateo,
not sure if I totally get what you're after, but maybe this helps:

SharpeRatio.annualized - function(roc){
 print(I'm computing the Sharpe Ratio)
 return()
}

MyF - function(Tic, price){
 print(Option 1)
 expr - expression(Ratio.Tic - SharpeRatio.annualized(roc))
 print(expr)
 eval(expr)
 print(Ratio.Tic)
 rm(Ratio.Tic)

 print(Option 2)
 expr - paste(Ratio., quote(Tic),  - 
SharpeRatio.annualized(roc), sep=)
 print(expr)
 eval(parse(text=expr))
 print(Ratio.Tic)
 rm(Ratio.Tic)

 print(Option 3)
 frmls - formals(MyF)
 expr - sapply(names(frmls), function(x){
 expr - substitute(NAME - SharpeRatio.annualized(roc),
 list(NAME=as.name(paste(Ratio, x, sep=.
 return(expr)
 })
 print(expr)
 sapply(expr, eval, envir=environment())
 print(Ratio.Tic)
 print(Ratio.Tic)
 print(Ratio.price)
 print(Ratio.price)
}
MyF()

Have fun with R!

Regards,
Janko

On 23.05.2011 23:31, MatAra wrote:
 Hello,

 I am stuck in a relatively simple procedure and was wondering if anybody
 knows the answer. I am a relatively new R user.

 How do I use an argument of a custom function in the name of a dataset in R?
 For example, I have the function:

 MyF- function(Tic, price){
   x
   x
   x
   Ratio.Tic- SharpeRatio.annualized(roc)
 }

 I would like to have a dataset that's labelled Ratio.MSFT, Ratio.XOM,
 Ratio.IBM...etc. The objective is to append multiple Ratio.Tic datasets that
 contains all the ratios in one single data.
 Thanks in for your time!
 Mateo


 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Passing-function-arguments-to-dataset-names-tp3545567p3545567.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] identical function names from 2 packages

2011-05-20 Thread Janko Thyson
.


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 


*Janko Thyson*
janko.thy...@ku-eichstaett.de mailto:janko.thy...@ku-eichstaett.de

Catholic University of Eichstätt-Ingolstadt
Ingolstadt School of Management
Statistics and Quantitative Methods
Auf der Schanz 49
D-85049 Ingolstadt

www.wfi.edu/lsqm http://www.wfi.edu/lsqm

Fon: +49 841 937-1923
Fax: +49 841 937-1965

This e-mail and any attachment is for authorized use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by any other party.
If you are not an intended recipient then please promptly delete this
e-mail and any attachment and all copies and inform the sender.


-- 


*Janko Thyson*
janko.thy...@googlemail.com mailto:janko.thy...@googlemail.com

Jesuitenstraße 3
D-85049 Ingolstadt

Mobile: +49 (0)176 83294257

This e-mail and any attachment is for authorized use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by any other party.
If you are not an intended recipient then please promptly delete this
e-mail and any attachment and all copies and inform the sender.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] identical function names from 2 packages

2011-05-20 Thread Janko Thyson
Thanks for the info.

I think I've tried that a while ago, but IIRCC, the problem was always 
that R won't let me create on object that would pass as a full grown 
NAMESPACE object.

  foo - function(x) print(x)
  assignInNamespace(x=foo, value=foo, ns=testNS)
Fehler in loadNamespace(name) : there is no package called 'testNS'

I've looked into this briefly:
?asNamespace
?attachNamespace

But there are no examples, so I don't really know how to use them ;-)

Regards,
Janko

On 20.05.2011 10:45, Barry Rowlingson wrote:
 On Fri, May 20, 2011 at 9:16 AM, Janko Thyson
 janko.thyson.rst...@googlemail.com  wrote:

 Yet, IMHO there will be more and more problems regarding this in the
 future as the number of contributed packages keeps growing. I personally
 would not mind at all to get used to typing 'thePackage::foo()' *all*
 the time, or at least have this as an option. In principal, this is no
 big deal once you actually *have* a true package with a namespace at
 hand. But what about the process of creating a package? AFAU, there is
 no way of simulating/emulating a namespace (which I understand is some
 special form of environment?) in order to be able to use '::' when
 creating/debugging functions that call other functions of the unfinished
 package. If anyone has some ideas on that one, I would appreciate to hear.
   there's some stuff in utils that might do it for you:

 Description:

   Utility functions to access and replace the non-exported functions
   in a name space, for use in developing packages with name spaces.

 Usage:

   getFromNamespace(x, ns, pos = -1, envir = as.environment(pos))

   assignInNamespace(x, value, ns, pos = -1,
 envir = as.environment(pos))

   fixInNamespace(x, ns, pos = -1, envir = as.environment(pos), ...)


 See ?assignInNamespace for the full info.

 Personally, I like the python way of doing things like this, and
 dealing with name clashes. You can do:

   import foo

 and then you do foo.bar(), foo.baz()

   or

 from foo import bar

 then you can just do bar(). There's also:

 from foo import *

   which lets you do bar(), baz(), but is frowned upon a bit because of
 possible name collisions. Or if you want to use functions with the
 same name from two packages you can do:

 from foo import bar as bar1
 from baz import bar as bar2

   Then you can do bar1() and bar2()

   Of course if you want to change anything in the bar package then
 similar hackery to the 'assignInNamespace' of R is necessary unless
 you want to rebuild the python package. Often called Monkey
 patching, I think, although this possibly only refers to mucking with
 class objects and methods.

 Barry



-- 


*Janko Thyson*
janko.thy...@googlemail.com mailto:janko.thy...@googlemail.com

Jesuitenstraße 3
D-85049 Ingolstadt

Mobile: +49 (0)176 83294257

This e-mail and any attachment is for authorized use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by any other party.
If you are not an intended recipient then please promptly delete this
e-mail and any attachment and all copies and inform the sender.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Flattening lists and environments (was: how to flatten a list to the same level?)

2011-05-19 Thread Janko Thyson

Dear list,

I came up with a two functions that flatten arbitrary deeply nested 
lists (as long as they're named; not tested for unnamed) and 
environments (see attachment; 'flatten_examples.txt' contains some 
examples).


The paradigm is somewhat similar to that implemented in 'unlist()', yet 
extends it. I would have very much liked to build upon the superfast 
functionality of 'unlist()', but there are some obstacles to this (see 
these two related posts at r-devel from today: 
https://stat.ethz.ch/pipermail/r-devel/2011-May/061070.html and 
https://stat.ethz.ch/pipermail/r-devel/2011-May/061071.html).


Therefore, I had to use a recursive looping paradigm. Yet, if anyone has 
some suggestions on how to speed things up (maybe some Rcpp-people feel 
called upon?!? ;-)), I'd appreciate any pointers. Yet I do hope that 
what I came up with is at least of some value for those that posted 
similar questions on how to flexibly flatten nested objects in the past 
(that's why I'm also referring to this older post below; I also build 
upon the code provided by Henrique Dallazuanna and Mark Heckmann).


Best regards,
Janko

PS: Maybe this should rather go into a blog-post, but I don't have one 
yet ;-)


On 19.05.2011 22:16, Janko Thyson wrote:
From: Mark Heckmann mark.heckmann_at_gmx.de 
mailto:mark.heckmann_at_gmx.de?Subject=Re:%20[R]%20how%20to%20flatten%20a%20list%20to%20the%20same%20level? 


Date: Sat, 09 Jan 2010 13:49:15 +0100

Henrique,

thanks for the code!! It works out fine for vectors. I forgot to 
mention I also have dataframes as list elements. Thus I want the 
structure of the list element to be kept intact.


I tried an recursive approach (which unfortunately resulted in some 
more code) which works.


.getNonListElements - function(x, env){

if(class(x)==list) {
for(i in seq(along=x)) .getNonListElements(x[[i]], env) # call
recursively
} else {
res- get(res, envir = env)  # get res from other 
env
res- c(res, list(x))# add one 
list element
assign(res, res, envir=env) # assign back to env
}

}

flattenList - function(l){

res- list() # make list object
env- environment()  # get current env  
 
.getNonListElements(l, env) # search for non list elements 
recursively
return(res)

}

l - list(DF=data.frame(A=c(1,2)), vec=c(a, b)) l - list(l,l)

 flattenList(l)

[[1]]

   A
1 1
2 2

[[2]]
[1] a b

[[3]]

   A
1 1
2 2

[[4]]
[1] a b

I am not sure if one can avoid the wrapper function or still use 
rapply to simplify the code. I do not know how. One more thing I would 
like to add are the objects names to the generated list. But I did not 
succeed in that.


Mark

Am 08.01.2010 um 18:29 schrieb Henrique Dallazuanna:

  Try something about like this:

  split(unlist(l), rep(1:length(idx- rapply(l, length)), idx))

  On Fri, Jan 8, 2010 at 1:35 PM, Mark Heckmannmark.heckmann_at_gmx.de
  wrote:
  I have a nested list l like:

  l- list(A=c(1,2,3), B=c(a, b))
  l- list(l,l, list(l,l))

  I want the list to be unlisted, but not on the lowest level of each
  branch.
  I want the lowest level of each list branch to remain as it is.
  So unlist or unlist(rec=F) do not work here as the level of nesting
  may
  differ on the elements.
  The result should look like:

  $A
  [1] 1 2 3

  $B
  [1] a b

  $A
  [1] 1 2 3

  $B
  [1] a b

  $A
  [1] 1 2 3

  $B
  [1] a b

  $A
  [1] 1 2 3

  $B
  [1] a b

  Any ideas?
  TIA!

  Mark


  
--
  Mark Heckmann
  Dipl. Wirt.-Ing. cand. Psych.
  Vorstraße 93 B01
  28359 Bremen
  Blog:www.markheckmann.de
  R-Blog:http://ryouready.wordpress.com

  __
  R-help_at_r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.




  -- 
  Henrique Dallazuanna

  Curitiba-Paraná-Brasil
  25° 25' 40 S 49° 16' 22 O

--

Mark Heckmann
Dipl. Wirt.-Ing. cand. Psych.
Vorstraße 93 B01
28359 Bremen
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.com
--


*Janko Thyson*
janko.thy...@ku-eichstaett.de mailto:janko.thy...@ku-eichstaett.de

Catholic University of Eichstätt-Ingolstadt
Ingolstadt School of Management
Statistics and Quantitative Methods
Auf der Schanz 49
D-85049 Ingolstadt

www.wfi.edu/lsqm http://www.wfi.edu/lsqm

Fon: +49 841 937-1923
Fax: +49 841 937-1965

This e-mail and any attachment is for authorized use by the intended
recipient(s) only. It may contain proprietary material

Re: [R] Remove all whitespaces

2011-05-05 Thread Janko Thyson
If your whitespace does not only contain regular spaces, this might also 
be useful:

x.1 - \t1 2 \n3   4
write(x.1, test.txt)
x.2 - readLines(test.txt)
x.3 - gsub([[:space:]], , x.2)
x - paste(x.3, collapse=)

See ?regex for details on regular expressions in R.

HTH,
Janko

On 05.05.2011 11:02, Ivan Calandra wrote:
 Hi Joel,

 Try this:
 x - 1 2 3 4 5 6 7 8 9 
 gsub( , , x)

 Ivan


 Le 5/5/2011 10:50, Joel a écrit :
 Hi

 I got a string that looks something like this

 1 2 3 4 5 6 7 8 9 ...

 and I want it to be

 123456789...

 So I want to remove all spaces (or whitespaces) from my string.

 Anyone know a good way of doing this?

 //Joel



-- 


*Janko Thyson*
janko.thy...@googlemail.com mailto:janko.thy...@googlemail.com

Jesuitenstraße 3
D-85049 Ingolstadt

Mobile: +49 (0)176 83294257

This e-mail and any attachment is for authorized use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by any other party.
If you are not an intended recipient then please promptly delete this
e-mail and any attachment and all copies and inform the sender.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Tone in mailing lists (was issue with strange characters (readHTMLTable))

2011-05-05 Thread Janko Thyson
   Isle   
 21�?�°54�¢�¤�²N
 160�?�°10�¢�¤�²W�¯�»�¿ / �¯�»�¿21.9�?�°N
 160.167�?�°W�¯�»�¿ / 21.9; -160.167
 
As you can see, there are weird characters in there. I have also 
 tried
readHTMLTable(u,  encoding = UTF-16) and readHTMLTable(u, encoding =
UTF-8)
but that didn't help.
It  seems to me that there may be an issue with the interaction of the
Windows settings of the character set.
sessionInfo() gives
  sessionInfo()
R version 2.13.0 (2011-04-13)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=Dutch_Netherlands.1252  LC_CTYPE=Dutch_Netherlands.1252
LC_MONETARY=Dutch_Netherlands.1252
[4] LC_NUMERIC=C   LC_TIME=Dutch_Netherlands.1252
attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
other attached packages:
[1] XML_3.2-0.2

I  have  also  attempted  to  let  R  use another setting by entering:
Sys.setlocale(LC_ALL, en_US.UTF-8), but this yields the response:
  Sys.setlocale(LC_ALL, en_US.UTF-8)
[1] 
Warning message:
In Sys.setlocale(LC_ALL, en_US.UTF-8) :
  OS reports request to set locale to en_US.UTF-8 cannot be honored

 In addition, I have attempted to make the change directly from the
 windows
command prompt, using: chcp 65001 and variations of that, but that
 didn't
change anything.
I have searched the list and the web and have found others bringing 
 forth
 a
similar issues, but have not been able to find a solution. I looks 
 like
 this
is  an  issue  of how Windows and R interact. Unfortunately, all three
 computers  at  my disposal have this problem. It occurs both under
 WinXP-x32
and under Win7-x86.
Is there a way to make R override the windows settings or can the 
 issue
 be
solved otherwise?
I have also tried other websites, and the issue occurs every time when
 there
is an �©, �¼, �¤, �®, et cetera in the text-to-be-scraped.
Thank you,
Roger
 __
 R-help@r-project.org  mailing list
 [2]https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 [3]http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 --
 Brian D. Ripley,rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  [4]http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595

 References

 1.http://en.wikipedia.org/wiki/Hawaii
 2.https://stat.ethz.ch/mailman/listinfo/r-help
 3.http://www.R-project.org/posting-guide.html
 4.http://www.stats.ox.ac.uk/%7Eripley/
 __
 R-help@r-project.org  mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 


*Janko Thyson*
janko.thy...@googlemail.com mailto:janko.thy...@googlemail.com

Jesuitenstraße 3
D-85049 Ingolstadt

Mobile: +49 (0)176 83294257

This e-mail and any attachment is for authorized use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by any other party.
If you are not an intended recipient then please promptly delete this
e-mail and any attachment and all copies and inform the sender.


On 05.05.2011 11:33, R.T.A.J.Leenders wrote:
 Thank you. The line of code you give certainly resolves several of the
 issues.
 I didn't realize that font support is such a tough matter to realize. Let 
 me
 express my gratitude to those who provide this for us in R.
 On 04-05-11, Prof Brian Ripleyrip...@stats.ox.ac.uk  wrote:

 Oh, please!
 This is about the contributed package XML, not R and not Windows.
 Some of us have worked very hard to provide reasonable font support in R,
 including on Windows.  We are given exceedingly little credit, just
 the brickbats for things for which we are not responsible.  (We even work
 hard to port XML to Windows for you, again with almost zero credit.)
 That URL is a page in UTF-8, as its header says.  We have provided many 
 ways
 to work with UTF-8 on Windows, but it seems readHTMLTable() is not making
 use of them.
 You need to run iconv() on the strings

[R] Feature request: rating/review system for R packages

2011-03-20 Thread Janko Thyson
Dear List,

 

I'm aware that this has been brought up before (e.g.
http://tolstoy.newcastle.edu.au/R/e6/help/09/03/7365.html
http://tolstoy.newcastle.edu.au/R/e6/help/09/03/7365.html ;
https://stat.ethz.ch/pipermail/r-help/2009-March/190902.html
https://stat.ethz.ch/pipermail/r-help/2009-March/190902.html), I couldn't
find anything recent on the topic, though.

 

After pondering all the pros and cons regarding the usefulness of a
rating/review system for R packages, don't you think it would make sense to
implement such a thing? Of course one could easily debate hours on how this
should exactly look like (quality vs. quantitiy/popularity and such), but
IMHO it would definitely be a start to have something like a simple version
Amazon's review system available. It would allow you to form at least an
initial opinion on purpose and quality of R packages before going at it. As
more and more packages pop up on CRAN, I think it'd be great to have such a
feature and that the time is ripe. 

 

Cheers,

Janko


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Referring to objects themselves

2011-03-19 Thread Janko Thyson
You might want to check out Reference Classes (?SetRefClass). The object
itself is stored in '.self' and can be referenced that way.

HTH,
Janko

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
Auftrag von Russ Abbott
Gesendet: Samstag, 19. März 2011 23:35
An: r-help@r-project.org
Betreff: [R] Referring to objects themselves

Is it possible to refer to an object from within a method, as in *this *in
Java?  I can't find anything about this in the documentation.  Sorry if I
missed it.

Thanks.

*-- Russ Abbott*
*_*
***  Professor, Computer Science*
*  California State University, Los Angeles*

*  Google voice: 747-*999-5105
*  blog: *http://russabbott.blogspot.com/
  vita:  http://sites.google.com/site/russabbott/
*_*

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Retrieve an index of nested lists | Changing name delimiter in 'unlist()'

2011-03-17 Thread Janko Thyson
Dear list,

I have to problems that are connected:

PROBLEM 1
I wonder if it is somehow possible to patch the function
'unlist(use.names=TRUE)' such that you can specify an arbitrary name
delimiter, e.g. / or _. As I often name my variables var.x.y, the
default delimiter makes it hard to distinguish the distinct layers of a
nested list after unlisting. 
As 'unlist()' it is called by '.Internal()', I didn't have a clue of how to
find the section where the names are pasted.

I'd like to use such a patched version in order to create a customized index
(class: data.frame) of nested lists which should look like this

name index  is.top  is.bottom   degree
a1  TRUEFALSE   1
a/a.11-1FALSE   FALSE   2
a/a.1/a.1.1  1-1-1  FALSE   TRUE3
a/a.21-2FALSE  FALSE   2
a/a.2/a.2.1  1-2-1  FALSE  TRUE3
b2  TRUE   FALSE   1
...

Of course I could get such an index by recursively traversing the list
layers, but this takes much too long. Maybe you also have another idea on
how to create such an index.

PROBLEM 2
I'd also like to retrieve such an index for nested environment structures.
Therefore, I would either need something similar to 'unlist()' that works on
environments or find something that coerces nested environments to nested
lists. Again, I solved this by recursively looping over the respective
environment layers, but it's too inefficient. Is there something out there
that does the job via a C routine somehow?
Thanks for any suggestions,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] WG: Reference classes: error with missing arguments in method calls

2011-03-06 Thread Janko Thyson
Dear list,

a while ago I posted this at r-devel but got no answers. Hope it’s okay to
give it a shot again by cross-posting it here.

TIA for any comments,
Janko

Von: Janko Thyson [mailto:janko.thyson.rst...@googlemail.com] 
Gesendet: Montag, 21. Februar 2011 00:58
An: r-devel@r-project. org (r-de...@r-project.org)
Betreff: Reference classes: error with missing arguments in method calls

Dear list,

I’m having problems in understanding an error that pops up in the context of
missing arguments with methods of reference class objects.

Because of the following statement taken from ‘?referenceClass’, my ref
class methods call explicit S4 methods:
“Reference methods should be kept simple; if they need to do some
specialized R computation, that computation should use a separate R function
that is called from the reference method“

So a ref class would look like this:
setRefClass(Class=Xmple, methods=list(foo=function(var.1, ...)
fooMthd(.self=.self, var.1=var.1, ...))) 

I’d like to keep the generics defs as simple as possible, thus their only
arg should be ‘.self’. The S4 methods are specified in a way that if ‘var.1’
is missing, it will be assigned some default value (I know I could
explicitly set the default value, yet I would like to rely on ‘missing()’
for that). Now, my problem is that this works fine if the generic contains
an argument ‘var.1’, but results in an error if it doesn’t. And I don’t
quite understand why since it seems to be related to whether the S4 method
is invoked from a call to a ref class method or not. Here’s an example which
demonstrates when it works as planed and when the error occurs. I tried to
keep as short as possible:

# 1) Stand-alone context
setGeneric(name=fooMthd, def=function(.self, ...)
standardGeneric(fooMthd), signature=c(.self))    

setMethod(f=fooMthd, signature=signature(.self=character), 
definition=function(.self, var.1, ...){
    cat(I'm having one additional argument compared to my generic:,
sep=\n)
    if(missing(var.1)) var.1 - some default value
    cat(paste(* var.1: , var.1, sep=), sep=\n)    
})

fooMthd(.self=blabla, var.1=hello world!)
fooMthd(.self=blabla) # Works.

#+

# 2) Reference class context
setMethod(f=fooMthd, signature=signature(.self=Xmple), 
definition=function(.self, var.1, ...){
    cat(I'm having one additional argument compared to my generic:,
sep=\n)
    if(missing(var.1)) var.1 - some default value
    cat(paste(* var.1: , var.1, sep=), sep=\n)    
})

setRefClass(Class=Xmple, methods=list(foo=function(var.1, ...)
fooMthd(.self=.self, var.1=var.1, ...)))

xmple - getRefClass(Class=Xmple)$new()
xmple$foo(var.1=hallo) 
xmple$foo() # Does not work.

#+

# 3) Fixed generic context
setGeneric(name=fooMthd, def=function(.self, var.1, ...)
standardGeneric(fooMthd), signature=c(.self)) 

setMethod(f=fooMthd, signature=signature(.self=Xmple), 
definition=function(.self, var.1, ...){
    cat(I'm having one additional argument compared to my generic:,
sep=\n)
    if(missing(var.1)) var.1 - some default value
    cat(paste(* var.1: , var.1, sep=), sep=\n)    
})

xmple$foo(var.1= blabla) 
xmple$foo() # Works.

I do understand that in the ref class ‘foo()’ has trouble passing an arg to
‘fooMthd()’ that hasn’t been specified. But why and how does simply
including ‘var.1’ in the generic def fix this?

Thanks for any comments,
Janko

R version 2.12.1 (2010-12-16)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C   
[5] LC_TIME=German_Germany.1252    

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

loaded via a namespace (and not attached):
[1] codetools_0.2-6 tools_2.12.1  

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] RCurl - HTTP request of header ONLY

2011-02-11 Thread Janko Thyson
Hi everyone,

I'm trying to send an HTTP request using RCurl that only requests the
response header, not the actual content. 
http://curl.haxx.se/docs/httpscripting.html says you can do this by using
the following option: curl --head http://www.something.com/

However, I can't figure out how to do this when using 'getURL()', for
example. 

Here's what I tried:
FIRST TRY
txt - getURL(http://www.something.com/;, verbose=TRUE, header=TRUE)
cat(txt)
This gives me header AND content.

SECOND TRY
headers - basicTextGatherer()
txt - getURL(http://www.something.com/;, header=TRUE, trace=TRUE,
headerfunction=headers$update)
cat(headers$value())
This gives me the header, but the content is also requested and sent to
'txt'.

I was looking for a RCurl option like 'head', but only found 'headerdata',
which I assumed is not what I want.

Then I also tried to understand what the individual RCurl options correspond
to in terms of the original libcurl options and found a respective section
in http://www.omegahat.org/RCurl/RCurlJSS.pdf (p. 10, The Request Options).
Since the name of the libcurl option is 'head', a corresponding RCurl
function should also be 'head'. Since it doesn't exist, I take it that it
hasn't been implemented (yet), correct? Is there another way to request
headers only?

Thanks a lot for any advice,
Janko

 Sys.info()
 sysname  release 
   Windows XP 
 version nodename 
build 2600, Service Pack 3   ASHB-109C-02 
 machinelogin 
   x86 wwa418 
user 
wwa418

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to catch error message

2010-11-26 Thread Janko Thyson
try.result - try(your.expr)

if(inherits(try.result, try-error)){
do.what.needs.to.be.done.here()
} else {
cat(OK, sep=\n)
}

Or have a look at ?tryCatch

Cheers,
Janko

 -Ursprüngliche Nachricht-
 Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 Im Auftrag von jim holtman
 Gesendet: Freitag, 26. November 2010 15:52
 An: Alla Bulashevska
 Cc: r-help@r-project.org
 Betreff: Re: [R] How to catch error message
 
 ?try
 
 On Fri, Nov 26, 2010 at 9:26 AM, Alla Bulashevska
 alla.bullashev...@fdm.uni-freiburg.de wrote:
  Dear R users,
  i would like to catch error message (coming after
  unsuccessful database query) so that the script will
  process further. How can I manage this?
  Thank you in Advance,
  Alla.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390
 
 What is the problem that you are trying to solve?
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Possible to pretty-printing using str()?

2010-11-23 Thread Janko Thyson
Dear list,

I'm looking for a suitable way to sort of one-line-pretty-print an
arbitrary R object in some of my log outputs.

Consider this:

cat(paste(The object/value is: , x, ., sep=), sep=\n)

No problem if x is of class:
  - character (length=1)
  - numeric   (length=1)
  - logical   (length=1)

For lengths  1 I can get around by paste(x, collapse=my.delimiter). So:

cat(paste(The object/value is: , paste(x, collapse=my.delimiter), .,
sep=), sep=\n)

Problem if x is of class
  - data.frame
  - matrix
  - list
  - other complex objects

For those objects something like the output of str() arranged in one line of
class 'character' would be great. 

Is that possible somehow?

Thanks for any comments,
Janko

## SYSTEM INFO ##
Windows XP SP3
R 2.12.0 (patched as of 2010-11-22)
Eclipse 3.6.1 (Helios)
StatET 0.9.x
###

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Possible to pretty-printing using str()?

2010-11-23 Thread Janko Thyson
A short annotation: 
I already considered deparsing the object via deparse(x), but that's not
exactly the info I'd like. I'm only interested in a short summary like str()
would give me, not in the deparsed object.

Thx,
Janko

## SYSTEM INFO ##
Windows XP SP3
R 2.12.0 (patched as of 2010-11-22)
Eclipse 3.6.1 (Helios)
StatET 0.9.x
###


 -Ursprüngliche Nachricht-
 Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 Im Auftrag von Janko Thyson
 Gesendet: Dienstag, 23. November 2010 20:32
 An: r-h...@r-project. org
 Betreff: [R] Possible to pretty-printing using str()?
 
 Dear list,
 
 I'm looking for a suitable way to sort of one-line-pretty-print an
 arbitrary R object in some of my log outputs.
 
 Consider this:
 
 cat(paste(The object/value is: , x, ., sep=), sep=\n)
 
 No problem if x is of class:
   - character (length=1)
   - numeric   (length=1)
   - logical   (length=1)
 
 For lengths  1 I can get around by paste(x, collapse=my.delimiter).
 So:
 
 cat(paste(The object/value is: , paste(x, collapse=my.delimiter),
 .,
 sep=), sep=\n)
 
 Problem if x is of class
   - data.frame
   - matrix
   - list
   - other complex objects
 
 For those objects something like the output of str() arranged in one
 line of
 class 'character' would be great.
 
 Is that possible somehow?
 
 Thanks for any comments,
 Janko
 
 ## SYSTEM INFO ##
 Windows XP SP3
 R 2.12.0 (patched as of 2010-11-22)
 Eclipse 3.6.1 (Helios)
 StatET 0.9.x
 ###
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Possible to pretty-printing using str()?

2010-11-23 Thread Janko Thyson
Aha: capture.output(str(x))

Sorry for the two previous eMails, but sometimes posting to the list helps
me thinking somehow ;-)

Greetz,
Janko

 -Ursprüngliche Nachricht-
 Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 Im Auftrag von Janko Thyson
 Gesendet: Dienstag, 23. November 2010 20:36
 An: 'r-h...@r-project. org'
 Betreff: Re: [R] Possible to pretty-printing using str()?
 
 A short annotation:
 I already considered deparsing the object via deparse(x), but that's
 not
 exactly the info I'd like. I'm only interested in a short summary like
 str()
 would give me, not in the deparsed object.
 
 Thx,
 Janko
 
 ## SYSTEM INFO ##
 Windows XP SP3
 R 2.12.0 (patched as of 2010-11-22)
 Eclipse 3.6.1 (Helios)
 StatET 0.9.x
 ###
 
 
  -Ursprüngliche Nachricht-
  Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org]
  Im Auftrag von Janko Thyson
  Gesendet: Dienstag, 23. November 2010 20:32
  An: r-h...@r-project. org
  Betreff: [R] Possible to pretty-printing using str()?
 
  Dear list,
 
  I'm looking for a suitable way to sort of one-line-pretty-print an
  arbitrary R object in some of my log outputs.
 
  Consider this:
 
  cat(paste(The object/value is: , x, ., sep=), sep=\n)
 
  No problem if x is of class:
- character (length=1)
- numeric   (length=1)
- logical   (length=1)
 
  For lengths  1 I can get around by paste(x, collapse=my.delimiter).
  So:
 
  cat(paste(The object/value is: , paste(x, collapse=my.delimiter),
  .,
  sep=), sep=\n)
 
  Problem if x is of class
- data.frame
- matrix
- list
- other complex objects
 
  For those objects something like the output of str() arranged in one
  line of
  class 'character' would be great.
 
  Is that possible somehow?
 
  Thanks for any comments,
  Janko
 
  ## SYSTEM INFO ##
  Windows XP SP3
  R 2.12.0 (patched as of 2010-11-22)
  Eclipse 3.6.1 (Helios)
  StatET 0.9.x
  ###
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-
  guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to get a specific named element in a nested list

2010-11-11 Thread Janko Thyson
What you want is some sort of indexing nested lists based on names (as we
are used to for vectors, for example). As Ivan pointed out, I don't think
there's an out-of-the-box function in R that supports such indexing as it
requires some sort of mapping of the nested list's hierarchical structure.
At first I thought one could use the information of 'as.relistable()' and
'relist()' in some way, but I couldn't really make use of it. 

So this is my own solution for retrieving all branch names of an arbitrary
deeply nested list together with their recursive indexes which you then can
use to index/access a branch of your choice. I'm sure there are more elegant
ways, but at least it does the trick ;-). Currently requires that all
branches are named and names at a branch are unique(!). E.g., this is fine:
my.list=list(a=list(a.1=list(...), a.2=list(...)), b=list(...)); something
like this is not supported yet: my.list=list(a=list(a.1=list(...),
a.1=list(...)), a=list(...))). One could use regular expressions to handle
stubs of names. Right now you must use the absolute path name (e.g.
a$a.1$a.1.1) of a branch to access it (you get this info via
'listnames.get()', though). But it should be easy to handle stubs (e.g.
a.1.1 only) as well.

The two function defs and an example:

# FUNCTION DEFS #

listnames.get - function(
list.obj,   
do.basename=FALSE,  
do.name.chain=TRUE,
...
)
{
# VALIDATE
if(!is.list(list.obj)) stop(Argument 'list.obj' must be a list.)
# /


#---
# CORE FUNCTION

#---

listnames.get.core - function(
# CUSTOM:
list.obj,   
do.basename=FALSE,
do.name.chain=TRUE,
buffer,
...
)
{   
if(!exists(index, buffer))
{
buffer$index- new.env(parent=emptyenv())
buffer$index- NULL
buffer$name - NULL
}
#x=1
jnk - sapply(1:length(list.obj), function(x)

{
list.branch - list.obj[x]
list.branch.nme - names(list.branch)
if(do.basename) list.branch.nme -
basename(list.branch.nme)
list.obj.updt   - list.branch[[1]]

# UPDATE BUFFER
buffer$run  - c(buffer$run, x)
if(do.name.chain)
{
#   buffer$name -
paste(buffer$name, list.branch.nme, sep=$)
buffer$name - c(buffer$name,
list.branch.nme)
} else
{
buffer$name - list.branch.nme
}
# /

index.crnt  -
paste(as.character(buffer$run), collapse=-)
index.crnt  - data.frame(
name=paste(buffer$name, collapse=$), 
index=index.crnt,
stringsAsFactors=FALSE
)
index.updt  - rbind(buffer$index,
index.crnt)
buffer$index- index.updt   

if(is.list(list.obj.updt))
{   
listnames.get.core(
list.obj=list.obj.updt,
do.basename=do.basename,
do.name.chain=do.name.chain,
buffer=buffer
)
}

# UPDATE BUFFER
buffer$run  - buffer$run[-length(buffer$run)]
buffer$name - buffer$name[-length(buffer$name)]

# /

return(NULL)
})

return(TRUE)
}

# /CORE FUNCTION --


#---
# APPLICATION

#---

assign(buffer, new.env(parent=emptyenv()), envir=environment())

listnames.get.core(

[R] Problems building own package (Error: package has been build before R-2.10.0)

2010-08-17 Thread Janko Thyson
Dear List,

 

I’m doing my first baby steps towards developing own R Packages and ran into
the following problem:

 

R CMD check mypackage works fine (no errors, no warnings)

R CMD build mypackage works fine (no errors, no warnings)

R CMD INSTALL –library=”C:\R\R-2.11.1\library”
“something\mypackage\mypackage_1.0.tar.gz” works fine (no errors, no
warnings)

 

However, when I try loading the package in an R-Session (version 2.11.1) via
“library(mypackage)”, R complains about the package being build before
version R-2.10.0 and tells me to rebuild it.

 

Could this possibly be due to the fact that I have multiple R versions
installed (this also includes the most recent one, though)? 

 

To provide you with some details:

-  Running Windows XP

-  All of my R versions are under “C:\R” (versions 2.9.2, 2.10.1,
2.11.1).

-  I installed Rtools (version 2.1.2) to “C:\Rtools” and pointed it
to “C:\R” (as this was the default) to interact with R (should this maybe
have been “C:\R\R-2.11.1”?). I also installed everything else necessary to
build packages (Inno Setup etc.).

-  My PATH is set up as explained in R-Admin manual. Also, the only
R version stated there is “C:\R\R-2.11.1\bin;”.

-  I updated the DESCRIPTION file and specified all .Rd files
correctly.

 

Any idea what I’m doing wrong?

 

Thanks a ton,

Janko

 

  _  

 

Janko Thyson
 mailto:holger.ko...@ku-eichstaett.de janko.thy...@ku-eichstaett.de

Catholic University of Eichstätt-Ingolstadt
Ingolstadt School of Management
Statistics and Quantitative Methods
Auf der Schanz 49
D-85049 Ingolstadt

 http://www.wfi.edu/lsqm www.wfi.edu/lsqm

Fon:  +49 841 937-1923
Fax:  +49 841 937-1965

This e-mail and any attachment is for authorized use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by any other party.
If you are not an intended recipient then please promptly delete this
e-mail and any attachment and all copies and inform the sender.

 

  _  

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] RMySQL: Slower parsing over time with htmlTreeParse()

2010-03-15 Thread Janko Thyson
Dear List,

 

has anyone of you experienced a significant increase in the time it takes to
parse an URL via htmlTreeParse() when this function is called repeatedly
every minute over a couple of hours?

 

Initially, a single parse takes about 0.5 seconds on my machine (Quad Core,
2.67 GHz, 8 MB RAM, Windows 7 64 Bit), . After some time, this can go up to
15 seconds or more.

 

I've tried garbage collect, catalogClearTable() (though I don't think that
has anything to do with the issue) and lately wondered if it maybe had to do
with the accumulation of errors over time (xmlErrorCumulator()). Are
parsing errors cumulated globally in the workspace over distinct calls to
this function? If so, is there a way to clean the buffer?

 

I would greatly appreciate if anyone had an idea about how to keep
request/parsing time fairly constant at the initial low level of 0.5
seconds.

 

Thanks a lot,

Janko


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] XML: Slower parsing over time with htmlTreeParse()

2010-03-15 Thread Janko Thyson
Sorry, I listed the wrong package in the header of my previous post!

 

 

 

Dear List,

 

has anyone of you experienced a significant increase in the time it takes to
parse an URL via htmlTreeParse() when this function is called repeatedly
every minute over a couple of hours?

 

Initially, a single parse takes about 0.5 seconds on my machine (Quad Core,
2.67 GHz, 8 MB RAM, Windows 7 64 Bit), . After some time, this can go up to
15 seconds or more.

 

I've tried garbage collect, catalogClearTable() (though I don't think that
has anything to do with the issue) and lately wondered if it maybe had to do
with the accumulation of errors over time (xmlErrorCumulator()). Are
parsing errors cumulated globally in the workspace over distinct calls to
this function? If so, is there a way to clean the buffer?

 

I would greatly appreciate if anyone had an idea about how to keep
request/parsing time fairly constant at the initial low level of 0.5
seconds.

 

Thanks a lot,

Janko


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Ubunut + Eclipse + StatET: Console terminates upon error

2010-03-11 Thread Janko Thyson
Dear List,

 

I'm trying to set up Eclispe (3.5.1) with the StatET-Plugin (0.8.1) under
Ubuntu (Karmic) and found it strange that my console terminates every time
something in a script produces an arbitrary error (e.g. just calling a
missing variable, trying to perform an illegal operation etc.). Can anyone
tell me why this happens or even better how to fix this?

 

Thanks a lot,

Janko


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Ubunut + Eclipse + StatET: Console terminates upon error

2010-03-11 Thread Janko Thyson
Thanks for the quick reply. I was following your hint with rJava, but I'm 
still a little lost.

I maybe should have added that the console terminating happens when launching 
it as Rterm, it works fine when running it as RJ. However, I would like to 
use Rterm. Here is what I did so far:

First of, I'm still confused about Ubuntu's sudo way of doing things. Not 
knowing how to authorize me as root when installing packages from a R-script, 
I can't write on /usr/local/lib/R/site-library or /usr/lib/R/site-library. 
So I turned to Synaptics, found and installed the CRAN package rJava that 
enables me to run the R console with Launch Type RJ within Eclipse. rJava 
went into /usr/lib. 

Then, launching R as RJ and trying to execute an install.packages(), Ubuntu 
prompted me for the specification of a valid library directory and offered to 
create /home/ME/i486-pc-linux-gnu-library/2.10. 

So .libPaths() would give me:
R .libPaths()
[1] /home/ME/i486-pc-linux-gnu-library/2.10 /usr/lib/R/site-library   

[3] /usr/lib/R/library   
R

I then tried to re-install the package rJava by install.packages() which 
got me the following output:

+

install.packages(rJava, repos=repos.cran, 
lib=/home/ME/R/i486-pc-linux-gnu-library/2.10)
trying URL 'http://cran.at.r-project.org/src/contrib/rJava_0.8-2.tar.gz'
Content type 'application/x-gzip' length 471971 bytes (460 Kb)
opened URL
==
downloaded 460 Kb

* installing *source* package ‘rJava’ ...
checking for gcc... gcc -std=gnu99
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc -std=gnu99 accepts -g... yes
checking for gcc -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking whether time.h and sys/time.h may both be included... yes
configure: checking whether gcc -std=gnu99 supports static inline...
yes
checking whether setjmp.h is POSIX.1 compatible... yes
checking whether sigsetjmp is declared... yes
checking whether siglongjmp is declared... yes
checking Java support in R... present:
interpreter : '/usr/bin/java'
archiver: '/usr/bin/jar'
compiler: '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags   : ''
java libs   : '-L/usr/lib/jvm/java-6-openjdk/jre/lib/i386/server 
-L/usr/lib/jvm/java-6-openjdk/jre/lib/i386 
-L/usr/lib/jvm/java-6-openjdk/jre/../lib/i386 -L -L/usr/java/packages/lib/i386 
-L/usr/lib/jni -L/lib -L/usr/lib -ljvm'
configure: error: One or more Java configuration variables are not set.
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.

If you don't have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.

ERROR: configuration failed for package ‘rJava’
* removing ‘/home/ME/R/i486-pc-linux-gnu-library/2.10/rJava’

The downloaded packages are in
‘/tmp/RtmpbGKuzS/downloaded_packages’
Warning message:
In install.packages(rJava, repos = repos.cran, lib = 
/home/ME/R/i486-pc-linux-gnu-library/2.10) :
  installation of package 'rJava' had non-zero exit status

+

So I ran sudo R CMD javareconf, but still get the same error.

Any hints from here on?

Thanks a lot!

Janko

-Ursprüngliche Nachricht-
Von: Dirk Eddelbuettel [mailto:e...@debian.org] 
Gesendet: Donnerstag, 11. März 2010 19:40
An: Janko Thyson
Cc: r-help@r-project.org; tobias.verb...@openanalytics.eu
Betreff: Re: [R] Ubunut + Eclipse + StatET: Console terminates upon error


On 11 March 2010 at 19:19, Janko Thyson wrote:
| I'm trying to set up Eclispe (3.5.1) with the StatET-Plugin (0.8.1) under
| Ubuntu (Karmic) and found it strange that my console terminates every time
| something in a script produces an arbitrary error (e.g. just calling a
| missing variable, trying to perform an illegal operation etc.). Can anyone
| tell me why this happens or even better how to fix this?

It so happens that I help a colleague recently to triage this.  The problem

[R] Possible to save workspace image including packages and class definitions?

2010-02-18 Thread Janko Thyson
Hi everyone!

 

Is it possible to save an image of the workspace where 

1)  Packages

2)  Classes

are saved along with the image?

 

Until now I only managed to save an workspace image that contained all
variables (including functions). When loading this image back into a new
session, packages and class defs where missing:

 

save.image(file=C:/temp/blabla.Rdata)

 

Thanks,

Janko

 

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Using Rscript in combination with eval() results in error

2010-02-11 Thread Janko Thyson

Dear List,

I'm having trouble running a .bat file which calls an R-Script via the
command line (using Rscript).

I put the following line in a file called test.bat:

Rscript --vanilla test.R

Then I tried to launch test.bat via Windows' CMD (I plan to make this a
scheduled Windows task).

The actual R-script (test.R) is executed just fine until it gets to a line
containing an eval() expression:

eval(parse(file=C:/temp/another.script.R))

and R (or Windows' CMD, respectively) throws the following error

Error in if (file == ) - stdin() else { : Argument is of length 0
Calls: source - eval.with.vis - eval.wtih.vis - source
Execution stopped

Usually such eval() expressions work just fine in my scripts.

I tried the following already:
1) to.load.file - file(C:/temp/another.script.R, open=rt);
eval(parse(file=to.load.file): No luck
2) Running test.R within a Rterm session: Works fine.
3) Calling the following from within a Rterm session:

system(Rscript C:/temp/test.R, wait=TRUE, invisible=FALSE)

That works too!

Is there something one needs to be aware of regarding eval() or source()
when launching a script via a CMD call to a .bat file?

Im running Windows XP and R-2.10.1

Any hints greatly appreciated!

Thanks,
Janko

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Can an object reference itself?

2010-01-18 Thread Janko Thyson
Hadley,

thanks for your comment. What you're saying is true, of course, and possibly
I did not really chose the best header to describe the actual issue I was
addressing. However, in the help archive I found something that gets me what
I want (calling a certain slot function without having to specify
arguments at calling time). I adapted it to my situation and maybe it's of
interest for someone facing a similar problem.

setClass(
Class=Testclass,
representation=representation(
env=environment,
data=function
)
)

data.fun - function(env) get(actual.data, env=env)

setMethod(
f=initialize, 
signature=signature(Testclass), 
definition=function(
.Object, 
actual.data=NULL, 
...
) {
 env- new.env(parent=emptyenv())
 env$actual.data- actual.data
 
data.fun.wrapper - function() data.fun(env)
 
 callNextMethod(.Object, env=env, data=data.fun.wrapper, ...)
}
)

obj - new(Testclass, actual.data=1:10)
o...@data()
o...@env$actual.data- 1:5
o...@data()

obj.mod - new(Testclass)
obj@env$actual.data - horst
obj@data()

Loading an object from harddrive could be implemented in a similar way by
putting the path-filename-combination in o...@env and adapting the function
data.fun() accordingly.

Putting data.fun() into the wrapper data.fun.wrapper() allows for
changes in data.fun() without having to re-source the method for
initialize() and to reassign obj each time.

Regards,
Janko

 -Ursprüngliche Nachricht-
 Von: hadley wickham [mailto:h.wick...@gmail.com]
 Gesendet: Freitag, 15. Januar 2010 19:35
 An: Janko Thyson
 Cc: r-help@r-project.org
 Betreff: Re: [R] Can an object reference itself?
 
 On Fri, Jan 15, 2010 at 5:30 PM, Janko Thyson
 janko.thy...@ku-eichstaett.de wrote:
  Dear List,
 
  I am not really familiar with any other language than R, but I’ve
 heard that
  in other languages there is something called “self referencing”.
 
  Here’s what I’m trying to get an answer for:
  Suppose there is a function that takes as its input a value of a slot
 of an
  S4 object. The function itself is stored in another slot of the SAME
 S4
  object. Is it then possible to have the function automatically
 “recognize”
  the name of the object in which slot it is placed via some sort of
 “self
  referencing” of the S4 object (to avoid having to explicitly state
 the
  required function argument for different S4 object instances with
 different
  names)?
 
  I hope the following code snippets will give you an idea what I’m
 trying to
  do:
 
  obj.for.slot - data.frame(a=1); obj.for.slot - data.frame(a=100)
  save(obj.for.slot, file=C:/obj.1.for.slot.Rdata);
 save(obj.for.slot,
  file=C:/obj.2.for.slot.Rdata)
 
  slotfun - function(obj.name)
  {
         file.fqn.char - paste(file.fqn - , obj.name, @file.fqn,
  sep=)
         eval(parse(text=file.fqn.char))
         load(file=file.fqn)
         return(obj.for.slot)
  }
 
  setClass(
         Class=Testclass,
         representation=representation(
                 file.fqn=character,
                 data=function
         ),
         prototype=prototype(
                 file.fqn=blabla,
                 data=slotfun
         )
  )
 
  test            - new(Testclass)
  test.mod        - new(Testclass)
 
 
  t...@file.fqn           - C:/obj.1.for.slot.Rdata
  test@file.fqn       - C:/obj.2.for.slot.Rdata
 
  t...@data(obj.name=test)
  test@data(obj.name=test.mod)
 
 An object does not have a unique name.  What would happen in the
 following situations?
 
 t3 - test.mod
 tests - list(
   test,
   test.mod
 )
 
 Hadley
 
 --
 http://had.co.nz/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Can an object reference itself?

2010-01-15 Thread Janko Thyson
Dear List,

I am not really familiar with any other language than R, but I’ve heard that
in other languages there is something called “self referencing”.

Here’s what I’m trying to get an answer for:
Suppose there is a function that takes as its input a value of a slot of an
S4 object. The function itself is stored in another slot of the SAME S4
object. Is it then possible to have the function automatically “recognize”
the name of the object in which slot it is placed via some sort of “self
referencing” of the S4 object (to avoid having to explicitly state the
required function argument for different S4 object instances with different
names)?

I hope the following code snippets will give you an idea what I’m trying to
do:

obj.for.slot - data.frame(a=1); obj.for.slot - data.frame(a=100)
save(obj.for.slot, file=C:/obj.1.for.slot.Rdata); save(obj.for.slot,
file=C:/obj.2.for.slot.Rdata)

slotfun - function(obj.name)
{ 
file.fqn.char - paste(file.fqn - , obj.name, @file.fqn,
sep=)
eval(parse(text=file.fqn.char))
load(file=file.fqn)
return(obj.for.slot)
}

setClass(
Class=Testclass,
representation=representation(
file.fqn=character,
data=function
),
prototype=prototype(
file.fqn=blabla,
data=slotfun
)
)

test- new(Testclass)
test.mod- new(Testclass)


t...@file.fqn   - C:/obj.1.for.slot.Rdata
test@file.fqn   - C:/obj.2.for.slot.Rdata

t...@data(obj.name=test)
test@data(obj.name=test.mod)

I'm trying to have slotfun() be stated in a way that does not require an
explicit stating of argument obj.name):
t...@data()
test@data()

Any hints in the right directions greatly appreciated!

Regards,
Janko Thyson

janko.thy...@kuei.de

Catholic University of Eichstätt-Ingolstadt
Ingolstadt School of Management
Statistics and Quantitative Methods
Auf der Schanz 49
D-85049 Ingolstadt

www.wfi.edu/lsqm

Fon:  +49 841 937-1923
Fax:  +49 841 937-1965

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Function nsl() missing in package utils

2009-08-21 Thread Janko Thyson
Dear list,

today I stumbled across the function „nsl()” for the first time in order to
perform a hostname lookup. According to the R Reference Index (Version
2.9.1, page 1522), the function should be part of the utils package.
However, I cannot find it in the utils package of my installation(s). I've
tried the R-versions 2.8.1, 2.9.0 and 2.9.1. 

I'd be very thankful if someone could give me a hint on nsl or some other
function to do a hostname lookup!

Regards,
Janko Thyson


Janko Thyson
janko.thy...@kuei.de

Catholic University of Eichstätt-Ingolstadt
Ingolstadt School of Management
Statistics and Quantitative Methods
Auf der Schanz 49
D-85049 Ingolstadt

www.wfi.edu/lsqm

Fon:  +49 841 937-1923
Fax:  +49 841 937-1965

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.