Displaying 20 results from an estimated 20000 matches similar to: "use "save.image" inside a function?"
2006 Apr 04
2
Return function from function with minimal environment
Hi,
this relates to the question "How to set a former environment?" asked
yesterday. What is the best way to to return a function with a
minimal environment from a function? Here is a dummy example:
foo <- function(huge) {
scale <- mean(huge)
function(x) { scale * x }
}
fcn <- foo(1:10e5)
The problem with this approach is that the environment of 'fcn' does
not
2008 Jul 01
2
ignore warning messages?
Hi All,
I'm working with R and want to ignore the warning messages given, is there a way to stop R from giving out warning messages any more?
an example:
tt = "test"
as.numeric(tt)
would give me the following message:
[1] NA
Warning message:
NAs introduced by coercion
I decide to ignore the warning message for now and don't want it to show any more, can someone help?
2011 Jan 05
1
RData size
Hi, I noticed a Rdata size issue that's puzzling to me. Attached find 2 example
datasets in text file. Both are 100x5, so the sizes for both text file are the
same. However, when I read them into R, the sizes are much different:
tt<-as.matrix(read.table("tt.txt",header=T,row.names=1))
save(tt,file='tt.RData')
2020 Oct 23
0
vanilla session in R Gui or RStudio
Can you be more specific about what conditions cause R to automatically load a package when a .RData file is loaded? My experience has actually been the opposite.
On October 22, 2020 6:13:11 PM PDT, Henrik Bengtsson <henrik.bengtsson at gmail.com> wrote:
>As Jeff says, it might be that you have a ~/.Rprofile file with
>instructions to load packages when R starts. It could also be
2007 Aug 22
3
integrate
Hi,
I am trying to integrate a function which is approximately constant
over the range of the integration. The function is as follows:
> my.fcn = function(mu){
+ m = 1000
+ z = 0
+ z.mse = 0
+ for(i in 1:m){
+ z[i] = rnorm(1, mu, 1)
+ z.mse = z.mse + (z[i] - mu)^2
+ }
+ return(z.mse/m)
+ }
> my.fcn(-10)
[1] 1.021711
> my.fcn(10)
[1] 0.9995235
> my.fcn(-5)
[1] 1.012727
> my.fcn(5)
2012 Nov 08
3
problem with package development and older defs earlier in search order
Hi,
I have a problem with a package I have developed in that functions do not get loaded due to older versions of the functions being in the .GlobalEnv? fetched from .Rdata files stored from previous saved workspaces. I need to be able to fix this somehow when I load the package. I do not want to mess up the search order to fix the problem.
How I got myself into this mess is that I started
2010 Jun 09
2
OOP and passing by value
Greetings,
I love the R system and am sincerely grateful for the great effort the
product and contributors
are delivering.
My question is as follows:
I am trying to use S4 style classes but cannot write functions that modify
an object
because paramter passing is by value.
For example I want to do this:
setGeneric("setData", function(this,fcn,k){ standardGeneric("setData")
2005 Oct 09
3
[ subscripting sometimes loses names (PR#8192)
--rwEMma7ioTxnRzrJ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
R, like recent versions of S-Plus, sometimes - but not always - loses
names when subscripting objects with "[". (Earlier versions of S and
S-Plus had the correct, name-preserving behavior.) This seems bad, it
would be better to remove names only by explicit request, not as an
accidental
2020 Oct 23
3
vanilla session in R Gui or RStudio
As Jeff says, it might be that you have a ~/.Rprofile file with
instructions to load packages when R starts. It could also be that
you have a .RData file, which is saved if you answer yes to:
> Save workspace image? [y/n/c]: y
when you quit R. If this file exists, then R loads it and all the
objects you had when you saved it. If there are objects associated
with packages, then that will
2016 Mar 13
1
formals(x)<- drops attributes including class
Just checking in to see whether it is intended or not that assigning
new formals to a function/closure causes any attributes to be dropped:
EXAMPLE:
> fcn <- structure(function() {}, foo="foo", class=c("foo"))
> str(fcn)
function ()
- attr(*, "srcref")=Class 'srcref' atomic [1:8] 1 18 1 30 18 30 1 1
.. ..- attr(*, "srcfile")=Classes
2006 Nov 16
2
.rdata files
Help! I accidentally saved my work as an .rdata format instead of .txt
I need to somehow get it saved as a .txt file otherwise i'm really in trouble!
Does anyone know how to convert .rdata to .txt files??
I also tried re-loading the file into R to see if i can re-save it but it doesnt work!
i've attached it below...
please help me asap! i need to turn it in as a .txt file
Thanks
2011 Mar 15
1
Problem with nls.lm function of minpack.lm package.
Dear R useRs,
I have a problem with nls.lm function of minpackl.lm package.
I need to fit the Van Genuchten Model to a set of data of Theta and hydraulic conductivity with nls.lm function of minpack.lm package.
For the first fit, the parameter estimates keep changing even after 1000 iterations (Th)
and
I have a following error message for fit of hydraulic conductivity (k);
Reason for
2003 Oct 30
2
'nls' and its arguments
Dear R experts!
I'd to fit data by 'nls' with me-supplied function 'fcn'.
1) I'd like 'fcn' to accept arbitrary arguments, i.e. I defined it
as f(...) {<body>}. (Ok, that's not actually impotant).
2) Second, I would NOT like to supply every parameter in the formula.
To illustrate this, let's look at the last example of 'nls' help
2010 May 14
1
debugging substitute function in R 2.11
Dear list,
A while ago I found in the web a function (sadly I can't credit the
author as I don't remember where I picked it up from) whose output is
a dataframe that lists for every object in the global environment its
class, mode, dim & length (where applicable). It is meant to be an
upgrade to the ls () function with a far more informative and detailed
output and it quickly became
2024 Feb 06
1
[EXTERNAL] Re: NOTE: multiple local function definitions for ?fun? with different formal arguments
Here's a dummy example that I think illustrates the problem:
toto <- function() {
if (runif(1) < 0.5)
function(a) a
else
function(a,b) a+b
}
> fcn <- toto()
> fcn(1,2)
[1] 3
> fcn <- toto()
> fcn(1,2)
[1] 3
> fcn <- toto()
> fcn(1,2)
Error in fcn(1, 2) : unused argument (2)
How can you use the returned function, if you get different arguments?
2013 Feb 05
1
integrate: Don't do this?
When I run the following function
HQ2 <- function(n) {
nv <- 6 * sqrt(n)
fcn <- function(z) {
pchisq(z^2 / 36, n - 1) * dnorm(nv - z)
}
## I want the integral from 0 to infinity:
f.Inf <- integrate(fcn, 0, Inf)
## Doc: "Don't do this":
f.100 <- integrate(fcn, 0, 100)
cbind(f.Inf, f.100)
}
I get, for n = 9 and
2008 Apr 22
4
how to convert non numeric data into numeric?
I am having the following error in my function
function(theta,reqdIRR)
{
theta1<-theta[1]
theta2<-theta[2]
n<-length(reqdIRR)
constant<- n*(theta1+theta2)
sum1<-lapply(reqdIRR*exp(theta1),FUN = sum)
sum2<-lapply(exp(theta2 - reqdIRR*exp(theta1)),FUN = sum)
sum = sum1 + sum2
log.fcn = constant - as.numeric(sum)
result = - log.fcn
return(result)
}
*error :
2010 Jul 09
4
Mysterious behavior
I had trouble with some tests for the survival suite last night that I
cannot explain.
Framework: Ubuntu Linux, R2.11.
For testing survival I have a separate directory and Makefile. I
pull everything into the local .RData, no packages, library, or
namespace. (It's easier to add test modifications to a routine in a
chain of calls).
A test of survreg + psline would fail because
2007 Sep 29
2
Help with functions (iterations)
Hello:
I am a bit confused by this problem. Can anyone give me some advice on this I would greatly appreciate it. Thank you for all your help.
Need to create a for loop that saves the estimate of pi from each 0f 100 separate iterations and store it in a numeric vector (of length 100). The for loop should be placed in a function that allows the user to vary the sample size, the simulation size,
2006 Mar 09
1
bugs in simtest (PR#8670)
# R for Windows will not send your bug report automatically.
# Please copy the bug report (after finishing it) to
# your favorite email program and send it to
#
# r-bugs at r-project.org
#
######################################################
This report is joint from Richard Heiberger <rmh at temple.edu>
and Burt Holland <bholland at temple.edu>.
Burt Holland is the coauthor