[Rd] additional examples for R-intro.texi (PR#7195)

bjg at network-theory.co.uk bjg at network-theory.co.uk
Tue Aug 24 13:00:06 CEST 2004


Here are some patches to expand some of the examples in R-intro.texi.

-- 
Brian Gough

Network Theory Ltd,
Publishing the R Reference Manuals --- http://www.network-theory.co.uk/R/

--- R-intro.texi~	Tue Aug 24 11:21:37 2004
+++ R-intro.texi	Tue Aug 24 11:21:37 2004
@@ -6288,6 +6288,21 @@
 use
 
 @example
+> help(package = "@var{name}")
+ at end example
+
+A complete list of the user-level objects in a package can be displayed
+using the command
+
+ at example
+> ls("package:@var{name}")
+ at end example
+
+For example, @code{ls("package:base")} displays all the base package
+commands.  Alternatively, if you have a web-browser available, you can
+use
+
+ at example
 > help.start()
 @end example
 
--- R-intro.texi~	Tue Aug 24 11:21:37 2004
+++ R-intro.texi	Tue Aug 24 11:21:37 2004
@@ -5019,6 +5019,31 @@
 
 After the fitting, @code{out$minimum} is the SSE, and
 @code{out$estimates} are the least squares estimates of the parameters.
+
+ at example
+> out
+$minimum
+[1] 1195.449
+
+$estimate
+[1] 212.68384222   0.06412146
+
+$gradient
+[1] -0.0001535012  0.0934206673
+
+$hessian
+            [,1]        [,2]
+[1,]    11.94725   -7661.319
+[2,] -7661.31875 8039421.153
+
+$code
+[1] 3
+
+$iterations
+[1] 26
+ at end example
+
+
 To obtain the approximate standard errors (SE) of the estimates we do:
 
 @example
@@ -5032,7 +5057,7 @@
 @example
 > plot(x, y)
 > xfit <- seq(.02, 1.1, .05)
-> yfit <- 212.68384222 * xfit/(0.06412146 + xfit)
+> yfit <- out$estimate[1] * xfit/(out$estimate[2] + xfit)
 > lines(spline(xfit, yfit))
 @end example
 
--- R-intro.texi~	Tue Aug 24 11:21:38 2004
+++ R-intro.texi	Tue Aug 24 11:21:38 2004
@@ -3307,8 +3307,8 @@
 @R{} is an expression language in the sense that its only command type
 is a function or expression which returns a result.  Even an assignment
 is an expression whose result is the value assigned, and it may be used
-wherever any expression may be used; in particular multiple assignments
-are possible.
+wherever any expression may be used; in particular, multiple assignments
+such as @code{x <- y <- z <- 0} are possible.
 
 Commands may be grouped together in braces, @code{@{@var{expr_1};
 @var{@dots{}}; @var{expr_m}@}}, in which case the value of the group
--- R-intro.texi~	Tue Aug 24 11:21:38 2004
+++ R-intro.texi	Tue Aug 24 11:21:38 2004
@@ -2021,9 +2021,8 @@
 @example
 > solve(A,b)
 @end example
-
 @noindent
-solves the system, returning @code{x} (up to some accuracy loss).
+solves the system @math{A x = b}, returning @code{x} (up to some accuracy loss).
 Note that in linear algebra, formally
 @eqn{@strong{x} = @strong{A}^{-1} @strong{b}, @code{x = A^@{-1@} %*% b}}
 where
--- R-intro.texi~	Tue Aug 24 11:21:39 2004
+++ R-intro.texi	Tue Aug 24 11:21:39 2004
@@ -413,7 +413,21 @@
 
 @findex help.search
 The @code{help.search} command allows searching for help in various
-ways: try @code{?help.search} for details and examples.
+ways: 
+
+ at example
+> help.search("linear models") 
+Help files with alias or title matching `linear models',
+type `help(FOO, package = PKG)' to inspect entry `FOO(PKG) TITLE':
+
+glm(base)               Fitting Generalized Linear Models
+lm(base)                Fitting Linear Models
+lm.fit(base)            Fitter Functions for Linear Models
+loglin(base)            Fitting Log-Linear Models
+......                  .......
+ at end example
+ at noindent
+Use the command @code{?help.search} for further details and examples.
 
 The examples on a help topic can normally be run by
 
--- R-intro.texi~	Tue Aug 24 11:21:39 2004
+++ R-intro.texi	Tue Aug 24 11:21:39 2004
@@ -3966,17 +3966,27 @@
     @}
   )
 @}
+ at end example
+The function can then be used as follows:
 
-ross <- open.account(100)
-robert <- open.account(200)
+ at example
+> ross <- open.account(100)
+> robert <- open.account(200)
 
-ross$withdraw(30)
-ross$balance()
-robert$balance()
+> ross$withdraw(30)
+30 withdrawn.  Your balance is 70
+> ross$balance()
+Your balance is 70 
+> robert$balance()
+Your balance is 200 
 
-ross$deposit(50)
-ross$balance()
-ross$withdraw(500)
+> ross$deposit(50)
+50 deposited.  Your balance is 120 
+> ross$balance()
+Your balance is 120 
+> ross$withdraw(500)
+Error in ross$withdraw(500) : You don't have that 
+  much money!
 @end example
 
 @node Customizing the environment, Object orientation, Scope, Writing your own functions
--- R-intro.texi~	Tue Aug 24 11:21:39 2004
+++ R-intro.texi	Tue Aug 24 11:21:39 2004
@@ -3848,6 +3848,17 @@
   fun1(f, a, b, fa, fb, a0, eps, lim, fun1)
 @}
 @end example
+ at noindent
+The following test cases demonstrate the use of this function:
+
+ at example
+> area(sqrt,0,1)
+0.6666557
+> testfn <- function(x) 1/(1+x^2)
+> area(testfn, 0, 100)
+1.560808
+ at end example
+
 
 @menu
 * Scope::



More information about the R-devel mailing list