Displaying 20 results from an estimated 30000 matches similar to: "Running an error-prone R script using 'source' command"
2009 Aug 13
4
un run run...
Hi All,
I am running an Rscript with a bunch of algorithms that are UNSTABLE
under some parameter settings.
At a certain point one of them sends error massage and my whole run STOPS!
What I would like is to save the error massage in some file or variable and
carry on to the next command line without stopping this run...
Any help or ideas would be welcome, please, with a concrete example
(not
2013 Mar 19
1
source, sys.source and error line numbers
Hi,
is there a way to retrieve the line number of where en error occurred when
sourcing a file in a tryCatch statement? Is it stored somewhere accessible?
It is not found in the error object.
Consider the following code/output and note the difference in the traceback
between source (has line number) and sys.source (has no line number).
Thank you,
Renaud
########
# code
########
codefile <-
2009 Oct 22
1
data frame is killing me! help
Usage
data(gasoline)
Format
A data frame with 60 observations on the following 2 variables.
octane
a numeric vector. The octane number.
NIR
a matrix with 401 columns. The NIR spectrum
and I see the gasoline data to see below
NIR.1686 nm NIR.1688 nm NIR.1690 nm NIR.1692 nm NIR.1694 nm NIR.1696 nm
NIR.1698 nm NIR.1700 nm
1 1.242645 1.250789 1.246626 1.250985 1.264189 1.244678 1.245913
2017 Jul 13
3
How to formulate quadratic function with interaction terms for the PLS fitting model?
I have two ideas about it.
1-
i) Entering variables in quadratic form is done with the command I
(variable ^ 2) -
plsr (octane ~ NIR + I (nir ^ 2), ncomp = 10, data = gasTrain, validation =
"LOO"
You could also use a new variable NIR_sq <- (NIR) ^ 2
ii) To insert a square variable, use syntax I (x ^ 2) - it is very
important to insert I before the parentheses.
iii) If you want to
2017 Jul 13
0
How to formulate quadratic function with interaction terms for the PLS fitting model?
Below.
-- Bert
Bert Gunter
On Thu, Jul 13, 2017 at 3:07 AM, Luigi Biagini <luigi.biagini at gmail.com> wrote:
> I have two ideas about it.
>
> 1-
> i) Entering variables in quadratic form is done with the command I
> (variable ^ 2) -
> plsr (octane ~ NIR + I (nir ^ 2), ncomp = 10, data = gasTrain, validation =
> "LOO"
> You could also use a new variable
2017 Jul 16
2
How to formulate quadratic function with interaction terms for the PLS fitting model?
> On Jul 13, 2017, at 7:43 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote:
>
> Below.
>
> -- Bert
> Bert Gunter
>
>
>
> On Thu, Jul 13, 2017 at 3:07 AM, Luigi Biagini <luigi.biagini at gmail.com> wrote:
>> I have two ideas about it.
>>
>> 1-
>> i) Entering variables in quadratic form is done with the command I
>>
2017 Jul 16
0
How to formulate quadratic function with interaction terms for the PLS fitting model?
??
If I haven't misunderstood, they are completely different!
1) NIR must be a matrix, or poly(NIR,...) will fail.
2) Due to the previously identified bug in poly, degree must be
explicitly given as poly(NIR, degree =2,raw = TRUE).
Now consider the following example:
> df <-matrix(runif(60),ncol=3)
> y <- runif(20)
> mdl1 <-lm(y~df*I(df^2))
> mdl2
2012 Oct 07
3
what exactly is the dim of data set yarn in package "pls"?
Hi list,
I am looking at the data yarn in package, I don't understand what is
dimension of this data set.
I did the following:
> library(pls)
> data(yarn)
> dim(yarn)
[1] 28 3
> head(yarn)
NIR.1 NIR.2 NIR.3 NIR.4 NIR.5 NIR.6 NIR.7 NIR.8 NIR.9
NIR.10 NIR.11
1 3.06630 3.08610 3.10790 3.09720 2.99790 2.82730 2.62330 2.40390 2.19310
2.00580 1.83790
2
2005 Apr 21
1
Strange data frame
Hello,
I'm playing around with the PLS package and found a data set (NIR) whose
structure I don't understand. Forgive me if this is a stupid question,
as I feel like it must be since I am less experienced with aspects of
modeling.
My problem, the pls NIR data frame does not seem to be a typical data
frame as, while it is a list, its variables are not of equal length.
Furthermore, I have
2017 Jul 13
2
Quadratic function with interaction terms for the PLS fitting model?
Dear all,
I am using the pls package of R to perform partial least square on a set of
multivariate data. Instead of fitting a linear model, I want to fit my
data with a quadratic function with interaction terms. But I am not sure
how. I will use an example to illustrate my problem:
Following the example in the PLS manual:
## Read data
data(gasoline)
gasTrain <- gasoline[1:50,]
## Perform
2017 Jul 13
0
Quadratic function with interaction terms for the PLS fitting model?
> On Jul 12, 2017, at 6:58 PM, Ng, Kelvin Sai-cheong <kscng at connect.hku.hk> wrote:
>
> Dear all,
>
> I am using the pls package of R to perform partial least square on a set of
> multivariate data. Instead of fitting a linear model, I want to fit my
> data with a quadratic function with interaction terms. But I am not sure
> how. I will use an example to
2017 Jul 13
0
Quadratic function with interaction terms for the PLS fitting model?
> On Jul 13, 2017, at 10:43 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote:
>
> poly(NIR, degree = 2) will work if NIR is a matrix, not a data.frame.
> The degree argument apparently *must* be explicitly named if NIR is
> not a numeric vector. AFAICS, this is unclear or unstated in ?poly.
I still get the same error with:
library(pld)
data(gasoline)
gasTrain <-
2019 Jun 08
2
Determining the exit code of an "almost finished" R script
Dear All,
I'm using "reg.finalizer" in a function that is to be called in R scripts
to do some cleanup on success. I have not found a way to run the function
only if the script run without errors, so when the exit code is expected to
be 0.
What I've tried is checking "geterrmessage()", but unfortunately it's not
perfect: if an error was handled with eg
2017 Dec 01
3
tryCatch in on.exit()
The following example involves a function whose on.exit()
expression both generates an error and catches the error.
The body of the function also generates an error.
When calling the function wrapped in a tryCatch, should
that tryCatch's error function be given the error from the
body of the function, since the one from the on.exit has
already been dealt with? Currently the outer tryCatch
2017 Jul 13
0
Quadratic function with interaction terms for the PLS fitting model?
Bert,
The 'degree' argument follows the "..." argument in the function declaration:
poly(x, ..., degree = 1, coefs = NULL, raw = FALSE, simple = FALSE)
Generally, any arguments after the "..." must be explicitly named, but as per the Details section of ?poly:
"Although formally degree should be named (as it follows ...), an unnamed second argument of length 1
2017 Jul 13
4
Quadratic function with interaction terms for the PLS fitting model?
poly(NIR, degree = 2) will work if NIR is a matrix, not a data.frame.
The degree argument apparently *must* be explicitly named if NIR is
not a numeric vector. AFAICS, this is unclear or unstated in ?poly.
-- Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom
2017 Jul 13
2
Quadratic function with interaction terms for the PLS fitting model?
Marc:
1. I am aware of the need to explicitly name arguments after ... --
see the R Language definition where this can be inferred from the
argument matching rules.
2. I am aware of the stated exception for poly(). However:
> x1 <- runif(20)
> x2 <- runif(20)
> mx <- cbind(x1,x2)
> poly(mx,2)
Error in poly(dots[[i]], degree, raw = raw, simple = raw) :
'degree'
2023 May 18
1
suprising behaviour of tryCatch()
G'day Federico,
On Wed, 17 May 2023 10:42:17 +0000
"Calboli Federico (LUKE)" <federico.calboli at luke.fi> wrote:
> sexsnp = rep(NA, 1750)
> for(i in 1:1750){tryCatch(sexsnp[i] = fisher.test(table(data[,3],
> data[,i + 38]))$p, error = function(e) print(NA))} Error: unexpected
> '=' in "for(i in 1:1750){tryCatch(sexsnp[i] ="
Try:
R> for(i in
2007 Feb 19
2
"try"ing to understand condition handling
I'm confused by the page documenting tryCatch and friends.
I think it describes 3 separate mechanisms: tryCatch (in which control
returns to the invoking tryCatch), withCallHandlers (in which control
goes up to the calling handler/s but then continues from the point at
which signalCondition() was invoked), and withRestarts (I can't tell
where control ends up).
For tryCatch the docs say
2023 May 17
4
suprising behaviour of tryCatch()
Hello,
I run a fisher.test() in a loop, with the issue that some of the data will not be useable. To protect the loop I used tryCatch but:
sexsnp = rep(NA, 1750)
for(i in 1:1750){tryCatch(sexsnp[i] = fisher.test(table(data[,3], data[,i + 38]))$p, error = function(e) print(NA))}
Error: unexpected '=' in "for(i in 1:1750){tryCatch(sexsnp[i] ="
But this works:
for(i in