Re: [R] R function stopped working

2017-04-04 Thread DANIEL PRECIADO
Thanks! I was not aware of the browser() function, seems pretty useful for 
debugging.
However, for this particular case, adding it to the mentioned function doesn't 
do much: Again I get no errors, no output in the terminal and no files are 
created.

If I include browser() within the for-loop (not defining it as a function, but 
running it directly), I do get to examine every step of the way, and it runs 
fine (as expected). But if the exact same for-loop is sitting inside a 
function, it doesn't do anything at all, with or without browser().

D.

On Tue, 2017-04-04 at 10:19 -0400, Boris Steipe wrote:

I discourage the use of print() for debugging.
Put a browser() statement into your loop and when execution takes you to the 
debugger interface, examine your variables and expressions one by one.


B.






On Apr 4, 2017, at 10:09 AM, DANIEL PRECIADO 
<danp...@hotmail.com<mailto:danp...@hotmail.com>> wrote:

To your first comment: Yes, the function used to work, and the loop inside it 
still does (as indicated in my first email). I wouldn't bother asking otherwise.
To your second, no, specifying the environment in the ls() call doesn't help, 
the problem persist.


On Tue, 2017-04-04 at 15:26 +0200, peter dalgaard wrote:

Given the following little experiment



foobar <- 1
f <- function() ls()
f()


character(0)


f <- function(x) ls()
f(2)


[1] "x"






... I am pretty sure that your code _never_ actually worked.

It probably helps if you tell ls() which environment to list, as in:



f <- function() ls(.GlobalEnv)
f()


[1] "f"  "foobar"




On 4 Apr 2017, at 12:27 , DANIEL PRECIADO 
<danp...@hotmail.com<mailto:danp...@hotmail.com><mailto:danp...@hotmail.com>> 
wrote:

Thanks, but printing doesn't work within the function either. (i.e, no
result or output, or error). Also, like I said, the loop is working
fine on its own (so the path, name, filename, and all other variables
called from the function exist, are available and are recognized just
fine). It just doesn't do anything (anymore) if the loop is inside a
function.


On Tue, 2017-04-04 at 11:21 +0200, peter dalgaard wrote:


How about inserting print() statements on the output of "ls()" and
the value of "filename". In particular, is the value of Plots_path
the same as last week?

-pd




On 4 Apr 2017, at 10:50 , DANIEL PRECIADO 
<danp...@hotmail.com<mailto:danp...@hotmail.com><mailto:danp...@hotmail.com>>
wrote:

The following function is supposed to search the workspace and save
plots  (i.e. listing all objects in the workspace named "Figs",
which
are all ggplot2 plots, and saving them as png files)

SaveFigs <- function()
{
   for (i in ls(pattern="_Figs_"))
   {
   filename = paste(Plots_Path, i, ".png", sep="")
   png(filename)
   print(eval(as.name(i)))
   dev.off()
   }
}


It was working perfectly until some days ago, but now nothing
happens
when the function is called. No error, no output, no result, no
files,
nothing at all. Completely useless.

If I run the for loop inside alone, without the function, it works
perfectly and produces the expected result (png files in the
defined
folder). But running it as a function doesn't do anything at all.

Can anyone explain why did this function simply and suddenly
stopped
working?

(using R version 3.3.3 on an ubuntu 16.10, if that is of any help)
__
R-help@r-project.org<mailto:R-help@r-project.org><mailto: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-g
uide.html
and provide commented, minimal, self-contained, reproducible code.











[[alternative HTML version deleted]]

__
R-help@r-project.org<mailto: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.





[[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] R function stopped working

2017-04-04 Thread DANIEL PRECIADO
To your first comment: Yes, the function used to work, and the loop inside it 
still does (as indicated in my first email). I wouldn't bother asking otherwise.
To your second, no, specifying the environment in the ls() call doesn't help, 
the problem persist.


On Tue, 2017-04-04 at 15:26 +0200, peter dalgaard wrote:

Given the following little experiment



foobar <- 1
f <- function() ls()
f()


character(0)


f <- function(x) ls()
f(2)


[1] "x"






... I am pretty sure that your code _never_ actually worked.

It probably helps if you tell ls() which environment to list, as in:



f <- function() ls(.GlobalEnv)
f()


[1] "f"  "foobar"




On 4 Apr 2017, at 12:27 , DANIEL PRECIADO 
<danp...@hotmail.com<mailto:danp...@hotmail.com>> wrote:

Thanks, but printing doesn't work within the function either. (i.e, no
result or output, or error). Also, like I said, the loop is working
fine on its own (so the path, name, filename, and all other variables
called from the function exist, are available and are recognized just
fine). It just doesn't do anything (anymore) if the loop is inside a
function.


On Tue, 2017-04-04 at 11:21 +0200, peter dalgaard wrote:


How about inserting print() statements on the output of "ls()" and
the value of "filename". In particular, is the value of Plots_path
the same as last week?

-pd




On 4 Apr 2017, at 10:50 , DANIEL PRECIADO 
<danp...@hotmail.com<mailto:danp...@hotmail.com>>
wrote:

The following function is supposed to search the workspace and save
plots  (i.e. listing all objects in the workspace named "Figs",
which
are all ggplot2 plots, and saving them as png files)

SaveFigs <- function()
{
for (i in ls(pattern="_Figs_"))
{
filename = paste(Plots_Path, i, ".png", sep="")
png(filename)
print(eval(as.name(i)))
dev.off()
}
}


It was working perfectly until some days ago, but now nothing
happens
when the function is called. No error, no output, no result, no
files,
nothing at all. Completely useless.

If I run the for loop inside alone, without the function, it works
perfectly and produces the expected result (png files in the
defined
folder). But running it as a function doesn't do anything at all.

Can anyone explain why did this function simply and suddenly
stopped
working?

(using R version 3.3.3 on an ubuntu 16.10, if that is of any help)
__
R-help@r-project.org<mailto: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-g
uide.html
and provide commented, minimal, self-contained, reproducible code.











[[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] R function stopped working

2017-04-04 Thread DANIEL PRECIADO
Thanks, but printing doesn't work within the function either. (i.e, no
result or output, or error). Also, like I said, the loop is working
fine on its own (so the path, name, filename, and all other variables
called from the function exist, are available and are recognized just
fine). It just doesn't do anything (anymore) if the loop is inside a
function.


On Tue, 2017-04-04 at 11:21 +0200, peter dalgaard wrote:
> How about inserting print() statements on the output of "ls()" and
> the value of "filename". In particular, is the value of Plots_path
> the same as last week?
> 
> -pd
> 
> 
> > On 4 Apr 2017, at 10:50 , DANIEL PRECIADO <danp...@hotmail.com>
> > wrote:
> > 
> > The following function is supposed to search the workspace and save
> > plots  (i.e. listing all objects in the workspace named "Figs",
> > which
> > are all ggplot2 plots, and saving them as png files)
> > 
> > SaveFigs <- function()
> > {
> > for (i in ls(pattern="_Figs_"))
> > {
> > filename = paste(Plots_Path, i, ".png", sep="")
> > png(filename)
> > print(eval(as.name(i)))
> > dev.off()
> > }
> > }
> > 
> > 
> > It was working perfectly until some days ago, but now nothing
> > happens
> > when the function is called. No error, no output, no result, no
> > files,
> > nothing at all. Completely useless.
> > 
> > If I run the for loop inside alone, without the function, it works
> > perfectly and produces the expected result (png files in the
> > defined
> > folder). But running it as a function doesn't do anything at all.
> > 
> > Can anyone explain why did this function simply and suddenly
> > stopped
> > working?
> > 
> > (using R version 3.3.3 on an ubuntu 16.10, if that is of any help)
> > __
> > 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-g
> > uide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> 
__
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] R function stopped working

2017-04-04 Thread DANIEL PRECIADO
The following function is supposed to search the workspace and save
plots  (i.e. listing all objects in the workspace named "Figs", which
are all ggplot2 plots, and saving them as png files)

SaveFigs <- function()
{
for (i in ls(pattern="_Figs_"))
{
filename = paste(Plots_Path, i, ".png", sep="")
png(filename)
print(eval(as.name(i)))
dev.off()
}
}


It was working perfectly until some days ago, but now nothing happens
when the function is called. No error, no output, no result, no files,
nothing at all. Completely useless.

If I run the for loop inside alone, without the function, it works
perfectly and produces the expected result (png files in the defined
folder). But running it as a function doesn't do anything at all.

Can anyone explain why did this function simply and suddenly stopped
working?

(using R version 3.3.3 on an ubuntu 16.10, if that is of any help)
__
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] nlmrt problems - No confInt, NA StdErr, t-, or p-values

2017-03-21 Thread DANIEL PRECIADO
Dear list,

I want to use nlxb (package nlmrt) to fit different datasets to a gaussian, 
obtain parameters (including standard error, t-and p-value) and confidence 
intervals.

nlxb generates the parameters, but very often results in NA standard 
error,t-and p-values. Furthermore, using confint() to obtain the confidence 
intervals generates a : Error in vcov.default(object) :   object does not have 
variance-covariance matrix" erro.

Can someone indicate why is nlxb generating NAs (when nls has no problem with 
them) and how to obtain confidence intervals from an nlmrt object?

Thanks


[[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] nls fitting & plotting to data subsets defined by combinations of categorical variables

2017-03-11 Thread DANIEL PRECIADO
Dear list, 

I want to apply the same nls function to different subsets of a larger
dataset. These subsets are defined as unique combinations of two
(categorical) variables, each one with two levels, so I should obtain 4
sets of parameters after fitting. 

I have managed to do it in a loop, creating different datasets for each
one of the sub-groups, and then applying the function to each one
independently and finally just merging all parameters in a single
dataset, but this seems pretty inefficient. 

I tried to use by and with, but they don't produce the expected result.
Rather, I get 4 sets of exactly the same parameters (?), so I know that
with/by are not actually doing anything, and the function is applied tothe 
dataset as a whole. 

Here is the call I tried to use:

test <- with(Data, by(Data, list(Type, Phase), function(x) nls(Response
~ k*exp(-((Duration-mu)^2)/(2*sigma^2)), start=c(mu=0,sigma=150,k=0.9),
upper=c(Inf, Inf, 1), algorithm="port", trace=T,
control=CSJ_FitControl)))

Also, I would like to plot the fitted distributions for each sub-group
in the same plot to be able to directly compare them. I figured that,
since I have the base nls function and the resulting parameters for
each subset (stored in a data frame), I should be able to enter these
on a ggplot call to get the 4 regressions lines plotted along with the
data, but I can't get that to work either. Or is it necessary to plot
this at the fitting stage (i.e. with the original data)?

Thanks for any suggestion   
__
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] R / G GUI freezes saving plot

2016-03-18 Thread Daniel Preciado
Randomly, whenever I try to save a plot, R becomes unresponsive and has to be 
killed. This happens almost every time.

R version 3.2.4 (2016-03-10) -- "Very Secure Dishes”
Platform: x86_64-apple-darwin13.4.0 (64-bit)
R.app GUI 1.67 (7152) x86_64-apple-darwin13.4.0
Os el capitan 10.11.3 (Although the problem was present in previous versions)

How to prevent this?




[[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] R / G GUI freezes saving plot

2016-03-18 Thread Daniel Preciado
No, nothing particular at all I would say. I generate plots either with 
functions from base R (such as plot() ) or ggplot2. Plotting functions are 
fine, so long as I don’t try to save them…. I also noted that the issue is most 
frequent when I save the plots from the menu (File>Save as) than if I save them 
from the command line using for example pdf() (But it still happens sometimes 
saving files from the command line).

From:  Jordan Meyer <jordanmeyer1...@gmail.com>
Date:  Friday 18 March 2016 at 14:30
To:  dp <danp...@hotmail.com>
Cc:  <r-help@r-project.org>
Subject:  Re: [R] R / G GUI freezes saving plot

Are there any particular types of plotting you are doing when it becomes 
unresponsive? If so, it would be helpful to see an example.

On Fri, Mar 18, 2016 at 5:45 AM, Daniel Preciado <danp...@hotmail.com> wrote:
Randomly, whenever I try to save a plot, R becomes unresponsive and has to be 
killed. This happens almost every time.

R version 3.2.4 (2016-03-10) -- "Very Secure Dishes”
Platform: x86_64-apple-darwin13.4.0 (64-bit)
R.app GUI 1.67 (7152) x86_64-apple-darwin13.4.0
Os el capitan 10.11.3 (Although the problem was present in previous versions)

How to prevent this?




[[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.



[[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.