Hello all, Hello Thomas Friedrichsmeier<br><br>[a] To not bore none with the entire email exchange being the context of this answer, I would like to point out the dates "4th march 2016" as well as "19th march 2016" and the rkwrad mailing list's archive address "https://mail.kde.org/pipermail/rkward-users/".<br>[b] To T. Friedrichsmeier: Thank you for your deliberate answers which I appreciate much. Aside from a number of mistakes I indeed made while trying to get the meaning of the R code examples (see email text dating to 19th march 2016 below), there is still something left that even the cited book (Norman Matloff, "The art of R programming", 2011, no starch press-for those interested) AFTER having read the accompanying text could not clarify (see [c]). Maybe this list is not the most appropriate place to try to discuss all of the following, though I had received the respective suggestions from here made me I come back on this subject HERE, too.<br>[c] Bits that need explanation/
comment:<br>[c1] 'example-page 163' The object "u" is introduced two pages earlier when it is assigned a discrete value. Taking even this value into account, my current rkward installed (0.6.1) using underlying R cannot assure that the very printed R code input is enabled to be performed from the mentioned pages 'properly' in the projected sense of that example complex. Now the reader of this book's section can only guess what misses to get the gotten right when they are no programmers, apparently,...<br>[c2] 'example-page 178' There is at least a good deal of similarity of the codes provided in the example by Mr Norman Matloff in the mail you referenced (https://stat.ethz.ch/pipermail/r-help/2010-October/255164.html) and the process of explanation BEFORE R code was introduced which was certainly to note. This is but somewhat UNHELPFUL when almost the rest of the process of building examples throughout Matloff's book follows the converse principle (which, in turn, makes it necessary
to spend time reading it wholly).<br>[c3] 'example-page 185' Clearly my fault because I omitted-in other words OVERREAD-intermittent R code. I was not yet able to fully grasp the recommended 'full-fledged' R code to tune in on the example's meaning...<br>[c4] 'example-page 213' I additionally to your indication (concerning the nature of the output) discovered an error committed: "n" previously was ONLY "n" (whatever [deleterious] effect such an impreciseness in that R code could have [had]...).<br>[c5] Uneasiness with examples of pages 277 and 310 (there included the following pages) has definitely not vanished. TO MAKE A LONG STORY SHORT: (i) Writing (and printing) functions in R without the proper number of curly braces still impedes them working. (ii) Gnawing off milliseconds or tenths of thousands of seconds (and below) might fail to be globally convincing. LONG STORY: (i) While the former (see c5-code, to follow below) has the quality of a conundrum to it owing to a
curly brace ("}") that is 'stubbornly' omitted no matter how long I stare at the code's printed to see where I might have NOT typed this closing curly brace which my eyes (and mind) cannot see on the respective page. (ii) The latter example seems problematic to me as here quite a false alarm is rung: Yes, the process time it takes to execute these 'dummy example function' versions differs by hundredths of seconds in favour of the second one cited-the handiness of the "apply()"-based third function version is not too dramatic because there we advance only incrementally by another few hundredths of a second; something which in reality with real problems might well be decisive loses some of its clout without teaching (to this reader) the whole beauty of process time reduction through vectorisation.<br>[c5-code]<br>> curve <- function(expr,from = NULL, to = NULL, n = 101, add = FALSE, type="l", ylab=NULL,log=NULL,xlim=NULL,...){<br>+ sexpr <- substitute(expr)<br>+
if(is.name(sexpr)){<br>+ x <- if (lg != "" && "x" %in% strsplit(lg, NULL)[[1]]){ # can you find the missing...<br>+ if(any(c(from,to) <= 0)) # ...curly brace? Me NOT.<br>+ stop("'from' and 'to' must be > 0 with log="x"")<br>+ exp(seq.int(log(from),log(to),length.out=n))<br>+ }<br>+ else seq.int(from,to,length.out=n)<br>+ y <- eval(expr,envir=list(x=x),enclos=parent.frame())<br>+ if(add)<br>+ lines(x,y,type=type,...)<br>+ else plot(x,y,type=type,ylab=ylab,xlim=xlim,log=lg,...)<br>+ }<br><br>Best regards (anyway...),<br>Markus Hofstetter<br><br><br><br>Thomas Friedrichsmeier <thomas.friedrichsmeier@ruhr-uni-bochum.de> schrieb (19.03.2016
22:48):<br><div style="border-left:#000000 2px solid; padding-left:5px;"><div style="font-family:courier; font-size:12px;">Hi!<br>
<br>
On Sat, 19 Mar 2016 02:44:04 +0100<br>
klerer@sxmail.de wrote:<br>
> [a] Concerning the "mask issue" (see email pre-dating today attached<br>
> below, reference 1) when one would use "rkward" frontend to work with<br>
> R and some 'quirky' behaviour that surfaced as a result of "masking"<br>
> event(s) when I executed some book examples (reference 2 below),<br>
> there may be some of these events that were probably also interesting<br>
> for the experienced "rkward" community. Thus, I would like to present<br>
> (see [b]) those instances to the "rkward" mailing list.<br>
<br>
Thanks. However, to put it quite bluntly, the problem does not seem to<br>
be in R, RKWard, or the book examples, but your understanding of what<br>
these are trying to demonstrate, and how. I would seriously recommend<br>
to take a step back, and shift your focus to understanding _in detail_<br>
what the easier examples are meant to demonstrate, before advancing to<br>
the more complex ones. I did not read through all your examples, but<br>
will give you some pointers on the first few, so you can see what I<br>
mean. <br>
<br>
[...]<br>
<br>
> (1)<br>
> page 163<br>
> > two <- function(u){ # Somehow, I<br>
> > obviously didn't get the idea of this example function; as an<br>
> > apparent stand-alone, "the<br>
> + assign("u",2*u,pos=.GlobalEnv) source" of<br>
> object "u" is obscured to this reader's eyes<br>
> + z <- 2*z<br>
> + }<br>
> > two(x)<br>
<br>
The idea is to demonstrate several aspects of variable scoping. You<br>
will really have to read the accompanying text to understand the<br>
meaning, here. "u" is the name of the function argument, and in this<br>
example set equal to "x". The example presumes that objects "x" and "z"<br>
exist in your workspace (and are numeric). Do they?<br>
<br>
> (2)<br>
> page 178<br>
> > x <- newtree(8,3) # Could that mean<br>
> > that the example running unto page 182 depended on this very<br>
> > function and the underlying<br>
> Fehler: konnte Funktion "newtree" nicht finden package (and,<br>
> additionally, which one package/ 'family' of packages)?<br>
<br>
So the function is not defined. Probably it has been defined in an<br>
earlier bit of code. Could be the one given, here(?):<br>
<br>
https://stat.ethz.ch/pipermail/r-help/2010-October/255164.html<br>
<br>
> (3)<br>
> page 185<br>
> > b <- newbookvec(c(3,4,5,5,12,13))<br>
> > b<br>
> $vec<br>
> [1] 3 4 5 5 12 13<br>
> <br>
> $wrts<br>
> [1] 0 0 0 0 0 0<br>
> <br>
> attr(,"class")<br>
> [1] "bookvec"<br>
> > b[2] # Now it is getting<br>
> > mysterious: According to the book (p. 185) "[1] 4" is the intended<br>
> > output + the call should have<br>
> basically referred to the<br>
> vector instead of the list, wright (wrong?)?<br>
> $wrts [1] 0 0 0 0 0 0<br>
> > b$vec[2] # ...in turn, one was<br>
> > probably wrong above when I was asking R the wrong question?!?<br>
> [1] 4<br>
> > b$vec[2] <- 88 # ...because of this,<br>
> > "b$vec[2]" would be apparently the better call rather than "b[2]";<br>
> > how high are the odds to call<br>
> this 'inconsequetial'<br>
> relative to what the book recommends???? inkonsequent NOMMA SCHAUN<br>
> > b$vec[2] <br>
> [1] 88<br>
> > b$wrts # "write count incremented?";<br>
> > that way (as 'prescribed' by the book) not at all... <br>
> [1] 0 0 0 0 0 0<br>
> > b[2] <- 88 # ... but that way the "write<br>
> > count" increased by one!?!!? What exactly is one to understand here<br>
> > right now...?? b[2]<br>
> $wrts<br>
> [1] 0 1 0 0 0 0<br>
<br>
Your are definitely missing vital parts of the example, here. The full<br>
example code is probably this one:<br>
https://stat.ethz.ch/education/semesters/ss2016/Progr_R3/bookvec-m.R<br>
<br>
Perhaps you mistyped on "[.bookvec" and "[<-.bookvec".<br>
<br>
Try pasting the full example in RKWard. It works just fine (and will<br>
also have worked with RKWard 0.6.1).<br>
<br>
> (4)<br>
> page 213<br>
> Text on page 213 says: "Essentially, J was treated as a list for<br>
> printing purposes. Now let's write our own print method:"<br>
> > print.employee <- function(wrkr){<br>
> + cat(wrkr$name,"n")<br>
> + cat("salary",wrkr$salary,"n")<br>
> + cat("union member",wrkr$union,"n") # "nothing" seriously<br>
> deleterious detected while copying-by-typing that function<br>
> <br>
> Text on page 213 further on says: "So, any call to print() on an<br>
> object of class "employee" should now be referred to<br>
> print.employee(). We can check that formally:"<br>
> > methods(,print.employee)<br>
> no methods were found<br>
<br>
Google books lets me view the example in the book, so I can tell you<br>
with authority: You were meant to type<br>
<br>
methods(,"employee")<br>
<br>
instead (aka "Show me the methods defined for class 'employee').<br>
"print.employee" is the expected output, here.<br>
<br>
[...]<br>
<br>
> (5)<br>
> Text on page 244 "The function write.table() works very much like<br>
> read.table(), except that it writes a data frame instead of reading<br>
> one. For instance, let's take the little Jack and Jill example from<br>
> the beginning of Chapter 5:"<br>
> > kids <- c("Jack","Jill")<br>
> > ages <- c(12,10)<br>
> > d <- data.frame(kids,ages,stringsAsFactors=FALSE)<br>
> > d<br>
> kids ages<br>
> 1 Jack 12<br>
> 2 Jill 10<br>
> > write.table(d,"kds")<br>
> > kds # Beginning with this line of R<br>
> > code, R complains that it cannot find/ recognise an object called<br>
> > "kds"!!! Where could it<br>
> have been gone?<br>
<br>
Why would it? The object is called "kids", not "kds". You are creating<br>
a _file_ called "kds" via write.table(), though.<br>
<br>
--<br>
<br>
I stopped, here. Again, please go slow, and focus on a solid<br>
understanding of the basics, first.<br>
<br>
As a second piece of generic advice, before assuming that the frontend<br>
is to blame, try pasting the same code into a console R session. Doing<br>
so will quickly rule out (or confirm) any suspicion in that direction.<br>
<br>
Regards<br>
Thomas</div></div>