Re: [R] function doesn't exists but still runs.....

2023-01-20 Thread akshay kulkarni
Dear Bill,
Thanks for your reply...If I run selenium() in debug mode,  
java_check() should work inside of selenium(), right?
Any other points to be considered when running selenium() in debug mode?

THanking you,
yours sincerely
AKSHAY M KULKARNI

From: Bill Dunlap 
Sent: Friday, January 20, 2023 5:32 AM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] function doesn't exists but still runs.

Look into R's scoping rules.  E.g., 
https://bookdown.org/rdpeng/rprogdatascience/scoping-rules-of-r.html.

* When a function looks up a name, it looks it up in the environment in which 
the function was defined.
* Functions in a package are generally defined in the package's environment 
(although sometimes they are in a descendent of the parent's environment).
* When one searches an environment for a name, if it is not found in the 
environment the search continues in the parent environment of that environment, 
recursively until the parent environment is the empty environment.

> with(environment(wdman::selenium), java_check)
function ()
{
javapath <- Sys.which("java")
if (identical(unname(javapath), "")) {
stop("PATH to JAVA not found. Please check JAVA is installed.")
}
javapath
}



-Bill

On Thu, Jan 19, 2023 at 2:28 PM akshay kulkarni 
mailto:akshay...@hotmail.com>> wrote:
dear members,
I am using the RSelenium package which uses the 
function selenium() from the wdman package. The selenium function contains the 
function java_check at line 12. If I try to run it, it throws an error:

>   javapath <- java_check()
Error in java_check() : could not find function "java_check"

Also:

> exists("java_check")
[1] FALSE

But when I run selenium(), it works fine

How do you explain this conundrum? You can refer to this link: 
https://github.com/ropensci/wdman/issues/15

Specifically what concept of R explains this weird behaviour?

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI


[[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] function doesn't exists but still runs..... (akshay kulkarni)

2023-01-20 Thread akshay kulkarni
Dear Jorgen,
 thanks for the reply.so according to you one can 
pegion hole the problem as concerning R's lexical scoping rules,am I right? Or 
some arcane concept regarding environments?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Jorgen Harmse 
Sent: Friday, January 20, 2023 9:34 PM
To: r-help@r-project.org ; akshay...@hotmail.com 
; williamwdun...@gmail.com 
Subject: Re: function doesn't exists but still runs. (akshay kulkarni)


It may help to expand a bit on Bill Dunlap's answer. I think that library does 
something like this:



Create a new environment for all the package objects. This environment will not 
be directly visible from .GlobalEnv, and ancestor environments may not be 
directly visible either. It may contain functions & other objects that are not 
exported, and it may use objects in ancestor environments that .GlobalEnv 
doesn't see directly. On the other hand, functions in the package will still 
see external functions in the way the package author intended instead of seeing 
functions with the same name that are visible to .GlobalEnv.



Run the source code in the private environment (using source(local=private 
environment, )?). Most package source code just defines functions, but the 
source code could build other objects that the package needs for some reason, 
or it could use delayedAssign to build the objects lazily. By default, the 
environment of any function defined by the source code is the private 
environment, so the function has access to private objects and to anything in 
ancestor environments.



Create a second new environment whose parent is parent.env(.GlobalEnv). For 
every export, assign the corresponding object from the private environment into 
the corresponding name in the public environment. Note that the environment of 
any function is still the private environment in which it was created. (I think 
that a function is mostly determined by its environment, its formals, and its 
body. A function call creates a new environment whose parent is the environment 
of the function. Thus whoever wrote the function can control the search for 
anything that isn�t passed in or created by the function itself.)



Reset parent.env(.GlobalEnv) to be the public environment. This makes all the 
exported objects (usually functions) available at the command line and allows 
the user to see everything that was available before (usually by name only, but 
by scope-resolved name if necessary). As noted by Bill Dunlap and in more 
detail above, package functions can use functions & other objects that are not 
directly visible to the user. As he also showed, you can (usually) pierce the 
privacy as long at least one function is exported. 
environment(package_function) is the private environment, so you can use it to 
see all the private objects and everything in the ancestor environments. You 
can repeat the trick to see private environments of packages you didn't 
directly pull in. I think you can even unlock bindings and do ghastly things to 
the package's private environment.



Regards,

Jorgen Harmse.

--

Message: 17
Date: Thu, 19 Jan 2023 16:02:31 -0800
From: Bill Dunlap 
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] function doesn't exists but still runs.
Message-ID:

Content-Type: text/plain; charset="utf-8"

Look into R's scoping rules.  E.g.,
https://bookdown.org/rdpeng/rprogdatascience/scoping-rules-of-r.html.

* When a function looks up a name, it looks it up in the environment in
which the function was defined.
* Functions in a package are generally defined in the package's environment
(although sometimes they are in a descendent of the parent's environment).
* When one searches an environment for a name, if it is not found in the
environment the search continues in the parent environment of that
environment, recursively until the parent environment is the empty
environment.

> with(environment(wdman::selenium), java_check)
function ()
{
javapath <- Sys.which("java")
if (identical(unname(javapath), "")) {
stop("PATH to JAVA not found. Please check JAVA is installed.")
}
    javapath
}



-Bill

On Thu, Jan 19, 2023 at 2:28 PM akshay kulkarni 
wrote:

> dear members,
> I am using the RSelenium package which uses
> the function selenium() from the wdman package. The selenium function
> contains the function java_check at line 12. If I try to run it, it throws
> an error:
>
> >   javapath <- java_check()
> Error in java_check() : could not find function "java_check"
>
> Also:
>
> > exists("java_check")
> [1] FALSE
>
> But when I run selenium(), it works fine
>
> How do you explain this conundrum? You can refer to this link:
> https://github.com/r

Re: [R] on parallel processing...

2022-11-04 Thread akshay kulkarni
dear Jeff,
 Yeah, you are right.just went through the documentation 
and found out that clusterApplyLB() from parallel package does the job... 
Thanks again

THanking you,
Yours sincerely
AKSHAY M KULKARNI

From: Jeff Newmiller 
Sent: Saturday, November 5, 2022 1:24 AM
To: r-help@r-project.org ; akshay kulkarni 
; R help Mailing list 
Subject: Re: [R] on parallel processing...

You don't specify processors. Just invoke the worker functions with the 
relevant packages and they will be allocated according to how you defined the 
cluster object... typically automatically. Processors are usually specified (to 
the cluster object) according to IP address. Cores within the processors are 
allocated according to how many processes are created.

Maybe you should read some documentation (vignettes), and/or look into 
R-sig-hpc (https://stat.ethz.ch/mailman/listinfo/r-sig-hpc). This is probably 
not the best place to pursue this.

On November 4, 2022 12:35:11 PM PDT, akshay kulkarni  
wrote:
>Dear members,
>  I want to send the same function with different 
> arguments to different processors. This solution was provided in Stack 
> Overflow 
> https://stackoverflow.com/questions/25045998/send-function-calls-with-different-arguments-to-different-processors-in-r-using
>[https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded]<https://stackoverflow.com/questions/25045998/send-function-calls-with-different-arguments-to-different-processors-in-r-using>
>Send function calls with different arguments to different processors in R 
>using parallel package - Stack 
>Overflow<https://stackoverflow.com/questions/25045998/send-function-calls-with-different-arguments-to-different-processors-in-r-using>
>Teams. Q for work. Connect and share knowledge within a single location that 
>is structured and easy to search. Learn more about Teams
>stackoverflow.com
>I have a 48 core processor. My question is, how do i loop through the cores 
>without explicitly mentioning the core numbers?
>Will this work?
>
>
>
>library(parallel)
>cl <- makeCluster(4)
>clusterExport(cl, "foo")
>cores <- seq_along(cl)
>r <- clusterApply(cl[cores], cores, function(core) {
>
>  for(i in 1:48) {
>
>  if (core ==i) {
>
>foo( x[i] )
>
>}
>}
>})
>
>Many thanks in advance..
>
>Thanking you,
>Your sincerely,
>AKSHAY M KULKARNI
>
>   [[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.

--
Sent from my phone. Please excuse my brevity.

[[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] on parallel processing...

2022-11-04 Thread akshay kulkarni
Dear members,
  I want to send the same function with different 
arguments to different processors. This solution was provided in Stack Overflow 
https://stackoverflow.com/questions/25045998/send-function-calls-with-different-arguments-to-different-processors-in-r-using
[https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded]
Send function calls with different arguments to different processors in R using 
parallel package - Stack 
Overflow
Teams. Q for work. Connect and share knowledge within a single location that 
is structured and easy to search. Learn more about Teams
stackoverflow.com
I have a 48 core processor. My question is, how do i loop through the cores 
without explicitly mentioning the core numbers?
Will this work?



library(parallel)
cl <- makeCluster(4)
clusterExport(cl, "foo")
cores <- seq_along(cl)
r <- clusterApply(cl[cores], cores, function(core) {

  for(i in 1:48) {

  if (core ==i) {

foo( x[i] )

}
}
})

Many thanks in advance..

Thanking you,
Your sincerely,
AKSHAY M KULKARNI

[[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] print and lapply....

2022-11-08 Thread akshay kulkarni
Dear Bert,
 Amazing! Very informative...THanks a lot.

From: Bert Gunter 
Sent: Tuesday, November 8, 2022 2:15 AM
To: akshay kulkarni 
Cc: Rui Barradas ; R help Mailing list 

Subject: Re: [R] print and lapply

" The lapply() caches the result, and prints the output of the
function in question  immediately after printing the final i. "

I don't believe you understand how lists or lapply works. You seem to
be trying to intuit from empirical behavior. Bad idea, if so. You need
to read the docs or spend time with suitable tutorials.

Consider:
lapply produces a **list,** each component of which is the result of
applying a function, FUN, to the components of its first argument
(here 1:4), which is itself a list. Results are **not** cached in the
sense you seem to think they are. The list object that is produced by
the function is **only** printed if you ask it to be (via cat, print,
or whatever) or, by default, if the result is unassigned. The default
printing can be turned off via the invisible() function.

So:

> res <- lapply(TP, function(x){
+print(x)
+x^2}
+)
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
## Nothing printed, but the results are the components of **list**
res, which can be printed on the console by print(res) or simply:

> res ## note the list syntax below
[[1]]
[1] 1

[[2]]
[1] 4

[[3]]
[1] 9

[[4]]
[1] 16

[[5]]
[1] 25

Now can you explain what happens here:

> invisible(lapply(TP, function(x){
+print(x)
+x^2}
+))
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
> ## results not printed; nothing assigned. Where can you find them? (See below)

or here:

> lapply(TP, function(x){
+print(x)
+x^2}
+)
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[[1]]
[1] 1

[[2]]
[1] 4

[[3]]
[1] 9

[[4]]
[1] 16

[[5]]
[1] 25

## How could you recover the results of the lapply and not just look
at the console printout if the results have not been assigned?
## Hint:  See ?.Last.value

-- Bert

On Mon, Nov 7, 2022 at 11:22 AM akshay kulkarni  wrote:
>
> Dear Rui,
>  THanks for your reply...The point is the loop is a scraping 
> code, and in your examples you have assumed that the body acts on i, the loop 
> variable. Can you adapt your code to JUST PRINT the loop variable i ?
>
> By the by, I think I have stumbled upon the answer: The lapply() caches the 
> result, and prints the output of the function in question  immediately after 
> printing the final i. The i's get printed serially, as the function 
> progresses
>
> > lapply(1:4,function(x){print(x);Sys.sleep(x^2);x^2})
> [1] 1
> [1] 2
> [1] 3
> [1] 4
> [[1]]
> [1] 1
>
> [[2]]
> [1] 4
>
> [[3]]
> [1] 9
>
> [[4]]
> [1] 16
>
> Here x^2 's print only after 4 is printed on the console
>
> tHanks anyways for your reply
>
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
> 
> From: Rui Barradas 
> Sent: Tuesday, November 8, 2022 12:24 AM
> To: akshay kulkarni ; R help Mailing list 
> 
> Subject: Re: [R] print and lapply
>
> �s 18:33 de 07/11/2022, akshay kulkarni escreveu:
> > Dear Rui,
> > Actually, I am replacing a big for loop by the lapply() 
> > function, and report the progress:
> >
> > lapply(TP, function(i) { BODY; print(i)})
> >
> > Can you please adjust your solution in this light?
> >
> > THanking you,
> > Yours sincerely,
> > AKSHAY M KULKARNI
> > ____
> > From: Rui Barradas 
> > Sent: Monday, November 7, 2022 11:59 PM
> > To: akshay kulkarni ; R help Mailing list 
> > 
> > Subject: Re: [R] print and lapply
> >
> > �s 17:17 de 07/11/2022, akshay kulkarni escreveu:
> >> Dear members,
> >>I have the following code and output:
> >>
> >>> TP <- 1:4
> >>> lapply(TP,function(x){print(x);x^2})
> >> [1] 1
> >> [1] 2
> >> [1] 3
> >> [1] 4
> >> [[1]]
> >> [1] 1
> >>
> >> [[2]]
> >> [1] 4
> >>
> >> [[3]]
> >> [1] 9
> >>
> >> [[4]]
> >> [1] 16
> >>
> >> How do I make the print function output x along with x^2, i.e not at the 
> >> beginning but before each of x^2?
> >>
> >> Many thanks in advance
> >>
> >> THanking you,
> >> Yours sincerely
> >> AKSHAY M KULKARNI
> >>
> >> [[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailm

Re: [R] print and lapply....

2022-11-08 Thread akshay kulkarni
Dear Tim,
   I think the recent replies from you, Bert and Rui cleared 
everything ...
THanks a lot..

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Ebert,Timothy Aaron 
Sent: Tuesday, November 8, 2022 2:15 AM
To: akshay kulkarni ; Bert Gunter 
; Andrew Simmons 
Cc: R help Mailing list 
Subject: RE: [R] print and lapply

Dear Akshay,
I think we have provided several solutions to the question asked. Can you 
please adjust your question to more closely align with what you need. It would 
be nice if you can provide sufficient detail so that we can see how you have 
adapted our solutions and how these have not quite addressed this problem.

Tim

-Original Message-
From: R-help  On Behalf Of akshay kulkarni
Sent: Monday, November 7, 2022 1:10 PM
To: Bert Gunter ; Andrew Simmons 
Cc: R help Mailing list 
Subject: Re: [R] print and lapply

[External Email]

Dear Bert,
   Actually, I am replacing a big for loop by the lapply() 
function, and report the progress:

lapply(TP, function(i) { BODY; print(i)})

Can you please adjust your solution in this light?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Bert Gunter 
Sent: Monday, November 7, 2022 11:16 PM
To: Andrew Simmons 
Cc: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] print and lapply

Well... yes, of course. But assuming the sole purpose is to print the results 
and not to save them for further processing, the OP's approach seems rather 
painful. My preference would be to vectorize:

> print(cbind(TP, TPsq =TP^2), print.gap = 3)
   TP   TPsq
[1,]1  1
[2,]2  4
[3,]3  9
[4,]4 16

See ?print.default for details

-- Bert


On Mon, Nov 7, 2022 at 9:20 AM Andrew Simmons  wrote:
>
> put print() around x^2
>
> On Mon, Nov 7, 2022, 12:18 akshay kulkarni  wrote:
>
> > Dear members,
> >  I have the following code and output:
> >
> > > TP <- 1:4
> > > lapply(TP,function(x){print(x);x^2})
> > [1] 1
> > [1] 2
> > [1] 3
> > [1] 4
> > [[1]]
> > [1] 1
> >
> > [[2]]
> > [1] 4
> >
> > [[3]]
> > [1] 9
> >
> > [[4]]
> > [1] 16
> >
> > How do I make the print function output x along with x^2, i.e not at
> > the beginning but before each of x^2?
> >
> > Many thanks in advance
> >
> > THanking you,
> > Yours sincerely
> > AKSHAY M KULKARNI
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fst
> > at.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=05%7C01%7Ctebert%4
> > 0ufl.edu%7Cb726a89349ed4860265708dac0eb5d0a%7C0d4da0f84a314d76ace60a
> > 62331e1b84%7C0%7C0%7C638034414365456384%7CUnknown%7CTWFpbGZsb3d8eyJW
> > IjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C300
> > 0%7C%7C%7Csdata=dQk1JPxWI4D0D6%2FSoC8LWw56749ulaFrGQc6affgBeM%3
> > Dreserved=0
> > PLEASE do read the posting guide
> > https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww
> > .r-project.org%2Fposting-guide.htmldata=05%7C01%7Ctebert%40ufl.
> > edu%7Cb726a89349ed4860265708dac0eb5d0a%7C0d4da0f84a314d76ace60a62331
> > e1b84%7C0%7C0%7C638034414365456384%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiM
> > C4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%
> > 7C%7Csdata=KDskHBxmxe0DV9XO7GvkESemUNTq2w%2BT%2Fro%2Bgb4DS2w%3D
> > reserved=0 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://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat
> .ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=05%7C01%7Ctebert%40ufl
> .edu%7Cb726a89349ed4860265708dac0eb5d0a%7C0d4da0f84a314d76ace60a62331e
> 1b84%7C0%7C0%7C638034414365456384%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4w
> LjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C
> sdata=dQk1JPxWI4D0D6%2FSoC8LWw56749ulaFrGQc6affgBeM%3Dreserv
> ed=0 PLEASE do read the posting guide
> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r
> -project.org%2Fposting-guide.htmldata=05%7C01%7Ctebert%40ufl.edu%
> 7Cb726a89349ed4860265708dac0eb5d0a%7C0d4da0f84a314d76ace60a62331e1b84%
> 7C0%7C0%7C638034414365612626%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwM
> DAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C
> sdata=OxZmpA4ORbfUq0gq

Re: [R] print and lapply....

2022-11-08 Thread akshay kulkarni
Dear Rui,
  The replies from you, Bert, Tim and solved my problem. My 
last question: what if I put print inside the body of the function passed on to 
lapply, instead of separately in the function argument of apply? Is this what 
you insinuated in your reply?

THanking you,
yours sincerely,
AKSHAY M KULKARNI

From: Rui Barradas 
Sent: Tuesday, November 8, 2022 2:20 AM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] print and lapply

�s 19:22 de 07/11/2022, akshay kulkarni escreveu:
> Dear Rui,
>   THanks for your reply...The point is the loop is a scraping 
> code, and in your examples you have assumed that the body acts on i, the loop 
> variable. Can you adapt your code to JUST PRINT the loop variable i ?
>
> By the by, I think I have stumbled upon the answer: The lapply() caches the 
> result, and prints the output of the function in question  immediately after 
> printing the final i. The i's get printed serially, as the function 
> progresses
>
>> lapply(1:4,function(x){print(x);Sys.sleep(x^2);x^2})
> [1] 1
> [1] 2
> [1] 3
> [1] 4
> [[1]]
> [1] 1
>
> [[2]]
> [1] 4
>
> [[3]]
> [1] 9
>
> [[4]]
> [1] 16
>
> Here x^2 's print only after 4 is printed on the console
>
> tHanks anyways for your reply
>
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
> ____
> From: Rui Barradas 
> Sent: Tuesday, November 8, 2022 12:24 AM
> To: akshay kulkarni ; R help Mailing list 
> 
> Subject: Re: [R] print and lapply
>
> �s 18:33 de 07/11/2022, akshay kulkarni escreveu:
>> Dear Rui,
>>  Actually, I am replacing a big for loop by the lapply() 
>> function, and report the progress:
>>
>> lapply(TP, function(i) { BODY; print(i)})
>>
>> Can you please adjust your solution in this light?
>>
>> THanking you,
>> Yours sincerely,
>> AKSHAY M KULKARNI
>> ________
>> From: Rui Barradas 
>> Sent: Monday, November 7, 2022 11:59 PM
>> To: akshay kulkarni ; R help Mailing list 
>> 
>> Subject: Re: [R] print and lapply
>>
>> �s 17:17 de 07/11/2022, akshay kulkarni escreveu:
>>> Dear members,
>>> I have the following code and output:
>>>
>>>> TP <- 1:4
>>>> lapply(TP,function(x){print(x);x^2})
>>> [1] 1
>>> [1] 2
>>> [1] 3
>>> [1] 4
>>> [[1]]
>>> [1] 1
>>>
>>> [[2]]
>>> [1] 4
>>>
>>> [[3]]
>>> [1] 9
>>>
>>> [[4]]
>>> [1] 16
>>>
>>> How do I make the print function output x along with x^2, i.e not at the 
>>> beginning but before each of x^2?
>>>
>>> Many thanks in advance
>>>
>>> THanking you,
>>> Yours sincerely
>>> AKSHAY M KULKARNI
>>>
>>>  [[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.
>> Hello,
>>
>> Here are two options, with ?cat and with ?message.
>>
>>
>> TP <- 1:4
>> lapply(TP, function(x){
>>  cat("x =", x, "x^2 =", x^2, "\n")
>> })
>>
>> lapply(TP, function(x){
>>  msg <- paste("x =", x, "x^2 =", x^2)
>>  message(msg)
>> })
>>
>>
>> Hope this helps,
>>
>> Rui Barradas
>>
>>
>>
> Hello,
>
>
> What do you want the lapply loop to return? If you have a BODY doing
> computations, do you want the lapply to return those values and report
> the progress?
>
> I have chosen cat or message over print because
>
>- cat returns invisible(NULL),
>- message returns invisible()
>- print returns a value, what it prints.
>
> Can you adapt the code below to your use case?
>
>
>
> TP <- 1:4
> lapply(TP, function(x, verbose = TRUE){
> # BODY
> y <- rnorm(100, mean = x)
>
> # show progress
> if(verbose)
>   cat("x =", x, "x^2 =", x^2, "\n")
>
> #return value
> c(x = x, mean = mean(y))
> })
>
> lapply(TP, function(x, verbose = TRUE){
> # BODY
> y <- rnorm(100, 

Re: [R] print and lapply....

2022-11-08 Thread akshay kulkarni
Dear Rui,
  THanks a lot!

THanking you,
Yours sincerely
AKSHAY M KULKARNI

From: Rui Barradas 
Sent: Tuesday, November 8, 2022 8:51 PM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] print and lapply

�s 14:47 de 08/11/2022, akshay kulkarni escreveu:
> Dear Rui,
>The replies from you, Bert, Tim and solved my problem. My 
> last question: what if I put print inside the body of the function passed on 
> to lapply, instead of separately in the function argument of apply? Is this 
> what you insinuated in your reply?
>
> THanking you,
> yours sincerely,
> AKSHAY M KULKARNI
> 
> From: Rui Barradas 
> Sent: Tuesday, November 8, 2022 2:20 AM
> To: akshay kulkarni ; R help Mailing list 
> 
> Subject: Re: [R] print and lapply....
>
> �s 19:22 de 07/11/2022, akshay kulkarni escreveu:
>> Dear Rui,
>>THanks for your reply...The point is the loop is a 
>> scraping code, and in your examples you have assumed that the body acts on 
>> i, the loop variable. Can you adapt your code to JUST PRINT the loop 
>> variable i ?
>>
>> By the by, I think I have stumbled upon the answer: The lapply() caches the 
>> result, and prints the output of the function in question  immediately after 
>> printing the final i. The i's get printed serially, as the function 
>> progresses
>>
>>> lapply(1:4,function(x){print(x);Sys.sleep(x^2);x^2})
>> [1] 1
>> [1] 2
>> [1] 3
>> [1] 4
>> [[1]]
>> [1] 1
>>
>> [[2]]
>> [1] 4
>>
>> [[3]]
>> [1] 9
>>
>> [[4]]
>> [1] 16
>>
>> Here x^2 's print only after 4 is printed on the console....
>>
>> tHanks anyways for your reply
>>
>> THanking you,
>> Yours sincerely,
>> AKSHAY M KULKARNI
>> 
>> From: Rui Barradas 
>> Sent: Tuesday, November 8, 2022 12:24 AM
>> To: akshay kulkarni ; R help Mailing list 
>> 
>> Subject: Re: [R] print and lapply
>>
>> �s 18:33 de 07/11/2022, akshay kulkarni escreveu:
>>> Dear Rui,
>>>   Actually, I am replacing a big for loop by the 
>>> lapply() function, and report the progress:
>>>
>>> lapply(TP, function(i) { BODY; print(i)})
>>>
>>> Can you please adjust your solution in this light?
>>>
>>> THanking you,
>>> Yours sincerely,
>>> AKSHAY M KULKARNI
>>> 
>>> From: Rui Barradas 
>>> Sent: Monday, November 7, 2022 11:59 PM
>>> To: akshay kulkarni ; R help Mailing list 
>>> 
>>> Subject: Re: [R] print and lapply
>>>
>>> �s 17:17 de 07/11/2022, akshay kulkarni escreveu:
>>>> Dear members,
>>>>  I have the following code and output:
>>>>
>>>>> TP <- 1:4
>>>>> lapply(TP,function(x){print(x);x^2})
>>>> [1] 1
>>>> [1] 2
>>>> [1] 3
>>>> [1] 4
>>>> [[1]]
>>>> [1] 1
>>>>
>>>> [[2]]
>>>> [1] 4
>>>>
>>>> [[3]]
>>>> [1] 9
>>>>
>>>> [[4]]
>>>> [1] 16
>>>>
>>>> How do I make the print function output x along with x^2, i.e not at the 
>>>> beginning but before each of x^2?
>>>>
>>>> Many thanks in advance
>>>>
>>>> THanking you,
>>>> Yours sincerely
>>>> AKSHAY M KULKARNI
>>>>
>>>>   [[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.
>>> Hello,
>>>
>>> Here are two options, with ?cat and with ?message.
>>>
>>>
>>> TP <- 1:4
>>> lapply(TP, function(x){
>>>   cat("x =", x, "x^2 =", x^2, "\n")
>>> })
>>>
>>> lapply(TP, function(x){
>>>   msg <- paste("x =", x, "x^2 =", x^2)
>>>   message(msg)
>>> })
>>>
>>>
>>> Hope this helps,
>>>
>>> 

Re: [R] print and lapply....

2022-11-07 Thread akshay kulkarni
Dear Tim,
   Actually, I am replacing a big for loop by the lapply() 
function, and report the progress:

lapply(TP, function(i) { BODY; print(i)})

Can you please adjust your solution in this light?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Ebert,Timothy Aaron 
Sent: Monday, November 7, 2022 11:07 PM
To: Andrew Simmons ; akshay kulkarni 
Cc: R help Mailing list 
Subject: RE: [R] print and lapply

Another option is use paste() within print()

lapply(TP,function(x){print(paste("x= ",x, " x^2 = ", x^2))})


Tim

-Original Message-
From: R-help  On Behalf Of Andrew Simmons
Sent: Monday, November 7, 2022 12:21 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] print and lapply

[External Email]

put print() around x^2

On Mon, Nov 7, 2022, 12:18 akshay kulkarni  wrote:

> Dear members,
>  I have the following code and output:
>
> > TP <- 1:4
> > lapply(TP,function(x){print(x);x^2})
> [1] 1
> [1] 2
> [1] 3
> [1] 4
> [[1]]
> [1] 1
>
> [[2]]
> [1] 4
>
> [[3]]
> [1] 9
>
> [[4]]
> [1] 16
>
> How do I make the print function output x along with x^2, i.e not at
> the beginning but before each of x^2?
>
> Many thanks in advance
>
> THanking you,
> Yours sincerely
> AKSHAY M KULKARNI
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat
> .ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=05%7C01%7Ctebert%40ufl
> .edu%7C28ae59febb2d43ce03b108dac0e46e79%7C0d4da0f84a314d76ace60a62331e
> 1b84%7C0%7C0%7C638034384601744085%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4w
> LjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C
> sdata=1D8FQ07q2NcYL8PaJW84PqdUAte3pZJy8XJuJXENbJ4%3Dreserved
> =0
> PLEASE do read the posting guide
> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r
> -project.org%2Fposting-guide.htmldata=05%7C01%7Ctebert%40ufl.edu%
> 7C28ae59febb2d43ce03b108dac0e46e79%7C0d4da0f84a314d76ace60a62331e1b84%
> 7C0%7C0%7C638034384601744085%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwM
> DAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C
> sdata=aEeZJ8FHVKGX%2BqOJaKskC1onjqKcON2Ux5cj3MimTGw%3Dreserved=0
> 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://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=05%7C01%7Ctebert%40ufl.edu%7C28ae59febb2d43ce03b108dac0e46e79%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638034384601744085%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=1D8FQ07q2NcYL8PaJW84PqdUAte3pZJy8XJuJXENbJ4%3Dreserved=0
PLEASE do read the posting guide 
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=05%7C01%7Ctebert%40ufl.edu%7C28ae59febb2d43ce03b108dac0e46e79%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638034384601744085%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=aEeZJ8FHVKGX%2BqOJaKskC1onjqKcON2Ux5cj3MimTGw%3Dreserved=0
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] print and lapply....

2022-11-07 Thread akshay kulkarni
Dear Rui,
 THanks for your reply...The point is the loop is a scraping 
code, and in your examples you have assumed that the body acts on i, the loop 
variable. Can you adapt your code to JUST PRINT the loop variable i ?

By the by, I think I have stumbled upon the answer: The lapply() caches the 
result, and prints the output of the function in question  immediately after 
printing the final i. The i's get printed serially, as the function 
progresses

> lapply(1:4,function(x){print(x);Sys.sleep(x^2);x^2})
[1] 1
[1] 2
[1] 3
[1] 4
[[1]]
[1] 1

[[2]]
[1] 4

[[3]]
[1] 9

[[4]]
[1] 16

Here x^2 's print only after 4 is printed on the console

tHanks anyways for your reply

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Rui Barradas 
Sent: Tuesday, November 8, 2022 12:24 AM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] print and lapply

�s 18:33 de 07/11/2022, akshay kulkarni escreveu:
> Dear Rui,
> Actually, I am replacing a big for loop by the lapply() 
> function, and report the progress:
>
> lapply(TP, function(i) { BODY; print(i)})
>
> Can you please adjust your solution in this light?
>
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
> 
> From: Rui Barradas 
> Sent: Monday, November 7, 2022 11:59 PM
> To: akshay kulkarni ; R help Mailing list 
> 
> Subject: Re: [R] print and lapply
>
> �s 17:17 de 07/11/2022, akshay kulkarni escreveu:
>> Dear members,
>>I have the following code and output:
>>
>>> TP <- 1:4
>>> lapply(TP,function(x){print(x);x^2})
>> [1] 1
>> [1] 2
>> [1] 3
>> [1] 4
>> [[1]]
>> [1] 1
>>
>> [[2]]
>> [1] 4
>>
>> [[3]]
>> [1] 9
>>
>> [[4]]
>> [1] 16
>>
>> How do I make the print function output x along with x^2, i.e not at the 
>> beginning but before each of x^2?
>>
>> Many thanks in advance
>>
>> THanking you,
>> Yours sincerely
>> AKSHAY M KULKARNI
>>
>> [[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.
> Hello,
>
> Here are two options, with ?cat and with ?message.
>
>
> TP <- 1:4
> lapply(TP, function(x){
> cat("x =", x, "x^2 =", x^2, "\n")
> })
>
> lapply(TP, function(x){
> msg <- paste("x =", x, "x^2 =", x^2)
> message(msg)
> })
>
>
> Hope this helps,
>
> Rui Barradas
>
>
>
Hello,


What do you want the lapply loop to return? If you have a BODY doing
computations, do you want the lapply to return those values and report
the progress?

I have chosen cat or message over print because

  - cat returns invisible(NULL),
  - message returns invisible()
  - print returns a value, what it prints.

Can you adapt the code below to your use case?



TP <- 1:4
lapply(TP, function(x, verbose = TRUE){
   # BODY
   y <- rnorm(100, mean = x)

   # show progress
   if(verbose)
 cat("x =", x, "x^2 =", x^2, "\n")

   #return value
   c(x = x, mean = mean(y))
})

lapply(TP, function(x, verbose = TRUE){
   # BODY
   y <- rnorm(100, mean = x)

   # show progress
   if(verbose) {
 msg <- paste("x =", x, "x^2 =", x^2)
 message(msg)
   }

   #return value
   c(x = x, mean = mean(y))
})



Hope this helps,

Rui Barradas


[[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] print and lapply....

2022-11-07 Thread akshay kulkarni
Dear Bert,
   Actually, I am replacing a big for loop by the lapply() 
function, and report the progress:

lapply(TP, function(i) { BODY; print(i)})

Can you please adjust your solution in this light?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Bert Gunter 
Sent: Monday, November 7, 2022 11:16 PM
To: Andrew Simmons 
Cc: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] print and lapply

Well... yes, of course. But assuming the sole purpose is to print the
results and not to save them for further processing, the OP's approach
seems rather painful. My preference would be to vectorize:

> print(cbind(TP, TPsq =TP^2), print.gap = 3)
   TP   TPsq
[1,]1  1
[2,]2  4
[3,]3  9
[4,]4 16

See ?print.default for details

-- Bert


On Mon, Nov 7, 2022 at 9:20 AM Andrew Simmons  wrote:
>
> put print() around x^2
>
> On Mon, Nov 7, 2022, 12:18 akshay kulkarni  wrote:
>
> > Dear members,
> >  I have the following code and output:
> >
> > > TP <- 1:4
> > > lapply(TP,function(x){print(x);x^2})
> > [1] 1
> > [1] 2
> > [1] 3
> > [1] 4
> > [[1]]
> > [1] 1
> >
> > [[2]]
> > [1] 4
> >
> > [[3]]
> > [1] 9
> >
> > [[4]]
> > [1] 16
> >
> > How do I make the print function output x along with x^2, i.e not at the
> > beginning but before each of x^2?
> >
> > Many thanks in advance
> >
> > THanking you,
> > Yours sincerely
> > AKSHAY M KULKARNI
> >
> > [[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.

[[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] print and lapply....

2022-11-07 Thread akshay kulkarni
Dear members,
 I have the following code and output:

> TP <- 1:4
> lapply(TP,function(x){print(x);x^2})
[1] 1
[1] 2
[1] 3
[1] 4
[[1]]
[1] 1

[[2]]
[1] 4

[[3]]
[1] 9

[[4]]
[1] 16

How do I make the print function output x along with x^2, i.e not at the 
beginning but before each of x^2?

Many thanks in advance

THanking you,
Yours sincerely
AKSHAY M KULKARNI

[[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] print and lapply....

2022-11-07 Thread akshay kulkarni
Dear Andrew
 It doesn't work:

> lapply(TP,function(x){print(x^2)})
[1] 1
[1] 4
[1] 9
[1] 16
[[1]]
[1] 1

[[2]]
[1] 4

[[3]]
[1] 9

[[4]]
[1] 16

Basically, lapply() is implemented by a for loop. So there must be some way 
right?

tHanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Andrew Simmons 
Sent: Monday, November 7, 2022 10:50 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] print and lapply

put print() around x^2

On Mon, Nov 7, 2022, 12:18 akshay kulkarni 
mailto:akshay...@hotmail.com>> wrote:
Dear members,
 I have the following code and output:

> TP <- 1:4
> lapply(TP,function(x){print(x);x^2})
[1] 1
[1] 2
[1] 3
[1] 4
[[1]]
[1] 1

[[2]]
[1] 4

[[3]]
[1] 9

[[4]]
[1] 16

How do I make the print function output x along with x^2, i.e not at the 
beginning but before each of x^2?

Many thanks in advance

THanking you,
Yours sincerely
AKSHAY M KULKARNI

[[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] print and lapply....

2022-11-07 Thread akshay kulkarni
Dear Rui,
   Actually, I am replacing a big for loop by the lapply() 
function, and report the progress:

lapply(TP, function(i) { BODY; print(i)})

Can you please adjust your solution in this light?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Rui Barradas 
Sent: Monday, November 7, 2022 11:59 PM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] print and lapply

�s 17:17 de 07/11/2022, akshay kulkarni escreveu:
> Dear members,
>   I have the following code and output:
>
>> TP <- 1:4
>> lapply(TP,function(x){print(x);x^2})
> [1] 1
> [1] 2
> [1] 3
> [1] 4
> [[1]]
> [1] 1
>
> [[2]]
> [1] 4
>
> [[3]]
> [1] 9
>
> [[4]]
> [1] 16
>
> How do I make the print function output x along with x^2, i.e not at the 
> beginning but before each of x^2?
>
> Many thanks in advance
>
> THanking you,
> Yours sincerely
> AKSHAY M KULKARNI
>
>[[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.
Hello,

Here are two options, with ?cat and with ?message.


TP <- 1:4
lapply(TP, function(x){
   cat("x =", x, "x^2 =", x^2, "\n")
})

lapply(TP, function(x){
   msg <- paste("x =", x, "x^2 =", x^2)
   message(msg)
})


Hope this helps,

Rui Barradas



[[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] lexical scoping for scripts......

2023-03-19 Thread akshay kulkarni
Dear Duncun,
 What if there is no interactive "session" running? I 
will be running my scripts automatically from crontab in Linux.

THanking you,
Yours sincerely,
AKSHAY M KULKARNI


From: Duncan Murdoch 
Sent: Monday, March 20, 2023 12:20 AM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] lexical scoping for scripts..

On 19/03/2023 2:33 p.m., akshay kulkarni wrote:
> Dear Duncun,
>   thanks for the reply
>
> So when I run a script in the system command line by R CMD BATCH, the
> objects created in the script cannot be stored in the workspace ,right?
> If yes, how to save them? Moreover, the only way to save the objects
> CREATED from the script permanently is to save them to the disk, right?

The objects you create *will* appear in the workspace of the session
that's running.  They won't be saved to disk automatically so they'll
disappear at the end of the BATCH run.   You can use various functions
(save(), save.image(), saveRDS(), writeLines(), etc.) to write them to
disk if you don't want them to disappear.

Duncan Murdoch


>
> THanking you,
> yours sincerely,
> AKSHAY M KULKARNI
> 
> *From:* Duncan Murdoch 
> *Sent:* Saturday, March 18, 2023 11:49 PM
> *To:* akshay kulkarni ; R help Mailing list
> 
> *Subject:* Re: [R] lexical scoping for scripts..
> On 18/03/2023 1:57 p.m., akshay kulkarni wrote:
>> Dear members,
>>   The documentation for source() says:
>>
>> Input is read and parsed from that file until the end of the file is 
>> reached, then the parsed expressions are evaluated sequentially in the 
>> chosen environment.
>>
>> What does this mean? I presume that any objects that are CREATED by the 
>> script are stored in the Global environment (if local = FALSE), but the 
>> rules for lexical scoping are the same as for functions, right?
>
> No, assignments will happen in the "chosen environment" as well.
>
> I'm not sure exactly what you mean about the rules for lexical scoping,
> but I think the answer is yes.  So if you do the following:
>
> Put this code in a file named "f.R":
>
> x <- 123
> f <- function() x
>
> and you run this code in your global environment:
>
> x <- 456
> e <- new.env()
> source("f.R", local = e)
>
> Then you'll find that x retains the value 456, and e$f() returns 123.
>
>>
>> Does the same apply for running the same script from the system command line 
>> by R CMD BATCH?
>
> I don't think R CMD BATCH has any equivalent to the local argument.
> Everything is evaluated in the global environment.
>
> Duncan Murdoch


[[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] lexical scoping for scripts......

2023-03-19 Thread akshay kulkarni
dear Duncun,
 got the pointthanks a lot..!

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Duncan Murdoch 
Sent: Monday, March 20, 2023 1:12 AM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] lexical scoping for scripts..

On 19/03/2023 2:55 p.m., akshay kulkarni wrote:
> Dear Duncun,
>   What if there is no interactive "session"
> running? I will be running my scripts automatically from crontab in Linux.

I was talking about the session that is created for the duration of the
BATCH run, not some other session that may be running in another
process.  Sorry for the confusion.

Duncan Murdoch

>
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
>
> 
> *From:* Duncan Murdoch 
> *Sent:* Monday, March 20, 2023 12:20 AM
> *To:* akshay kulkarni ; R help Mailing list
> 
> *Subject:* Re: [R] lexical scoping for scripts..
> On 19/03/2023 2:33 p.m., akshay kulkarni wrote:
>> Dear Duncun,
>>   thanks for the reply
>>
>> So when I run a script in the system command line by R CMD BATCH, the
>> objects created in the script cannot be stored in the workspace ,right?
>> If yes, how to save them? Moreover, the only way to save the objects
>> CREATED from the script permanently is to save them to the disk, right?
>
> The objects you create *will* appear in the workspace of the session
> that's running.  They won't be saved to disk automatically so they'll
> disappear at the end of the BATCH run.   You can use various functions
> (save(), save.image(), saveRDS(), writeLines(), etc.) to write them to
> disk if you don't want them to disappear.
>
> Duncan Murdoch
>
>
>>
>> THanking you,
>> yours sincerely,
>> AKSHAY M KULKARNI
>> ----
>> *From:* Duncan Murdoch 
>> *Sent:* Saturday, March 18, 2023 11:49 PM
>> *To:* akshay kulkarni ; R help Mailing list
>> 
>> *Subject:* Re: [R] lexical scoping for scripts..
>> On 18/03/2023 1:57 p.m., akshay kulkarni wrote:
>>> Dear members,
>>>   The documentation for source() says:
>>>
>>> Input is read and parsed from that file until the end of the file is 
>>> reached, then the parsed expressions are evaluated sequentially in the 
>>> chosen environment.
>>>
>>> What does this mean? I presume that any objects that are CREATED by the 
>>> script are stored in the Global environment (if local = FALSE), but the 
>>> rules for lexical scoping are the same as for functions, right?
>>
>> No, assignments will happen in the "chosen environment" as well.
>>
>> I'm not sure exactly what you mean about the rules for lexical scoping,
>> but I think the answer is yes.  So if you do the following:
>>
>> Put this code in a file named "f.R":
>>
>> x <- 123
>> f <- function() x
>>
>> and you run this code in your global environment:
>>
>> x <- 456
>> e <- new.env()
>> source("f.R", local = e)
>>
>> Then you'll find that x retains the value 456, and e$f() returns 123.
>>
>>>
>>> Does the same apply for running the same script from the system command 
>>> line by R CMD BATCH?
>>
>> I don't think R CMD BATCH has any equivalent to the local argument.
>> Everything is evaluated in the global environment.
>>
>> Duncan Murdoch
>


[[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] lexical scoping for scripts......

2023-03-19 Thread akshay kulkarni
Dear Duncun,
 thanks for the reply

So when I run a script in the system command line by R CMD BATCH, the objects 
created in the script cannot be stored in the workspace ,right? If yes, how to 
save them? Moreover, the only way to save the objects CREATED from the script 
permanently is to save them to the disk, right?

THanking you,
yours sincerely,
AKSHAY M KULKARNI

From: Duncan Murdoch 
Sent: Saturday, March 18, 2023 11:49 PM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] lexical scoping for scripts..

On 18/03/2023 1:57 p.m., akshay kulkarni wrote:
> Dear members,
>   The documentation for source() says:
>
> Input is read and parsed from that file until the end of the file is reached, 
> then the parsed expressions are evaluated sequentially in the chosen 
> environment.
>
> What does this mean? I presume that any objects that are CREATED by the 
> script are stored in the Global environment (if local = FALSE), but the rules 
> for lexical scoping are the same as for functions, right?

No, assignments will happen in the "chosen environment" as well.

I'm not sure exactly what you mean about the rules for lexical scoping,
but I think the answer is yes.  So if you do the following:

Put this code in a file named "f.R":

   x <- 123
   f <- function() x

and you run this code in your global environment:

   x <- 456
   e <- new.env()
   source("f.R", local = e)

Then you'll find that x retains the value 456, and e$f() returns 123.

>
> Does the same apply for running the same script from the system command line 
> by R CMD BATCH?

I don't think R CMD BATCH has any equivalent to the local argument.
Everything is evaluated in the global environment.

Duncan Murdoch

[[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] lexical scoping for scripts......

2023-03-19 Thread akshay kulkarni
Dear Jeff,
 I will not be running R command in the shell prompt. So there 
is no banner, no > prompt. Just running "myscript.R" from the shell prompt. or 
from crontab in Linux. I think you get the context.

thanking you,
yours sincerely
AKSHAY M KULKARNI


From: Jeff Newmiller 
Sent: Monday, March 20, 2023 1:01 AM
To: r-help@r-project.org ; akshay kulkarni 
; Duncan Murdoch ; R help 
Mailing list 
Subject: Re: [R] lexical scoping for scripts..

What do _you_ mean when you use the term "interactive"? Because R distinguishes 
between executing code in a function and executing code from the global 
environment, but it does not care whether a person is doing the typing or not.

I get the feeling that you think of your R code in terms of "scripts" when you 
should be thinking of your code in terms of functions. What parameters do you 
give to them, and what values do they return. Where you put those return values 
is up to you... how do you save them now? (Depending on auto-saving to .Rdata 
files is not a good idea in any case, but if you choose to use save() to 
specific filename.Rdata files works the same whether you type it interactively 
or use R CMD BATCH.

On March 19, 2023 11:55:37 AM PDT, akshay kulkarni  
wrote:
>Dear Duncun,
> What if there is no interactive "session" running? I 
> will be running my scripts automatically from crontab in Linux.
>
>THanking you,
>Yours sincerely,
>AKSHAY M KULKARNI
>
>____
>From: Duncan Murdoch 
>Sent: Monday, March 20, 2023 12:20 AM
>To: akshay kulkarni ; R help Mailing list 
>
>Subject: Re: [R] lexical scoping for scripts..
>
>On 19/03/2023 2:33 p.m., akshay kulkarni wrote:
>> Dear Duncun,
>>   thanks for the reply
>>
>> So when I run a script in the system command line by R CMD BATCH, the
>> objects created in the script cannot be stored in the workspace ,right?
>> If yes, how to save them? Moreover, the only way to save the objects
>> CREATED from the script permanently is to save them to the disk, right?
>
>The objects you create *will* appear in the workspace of the session
>that's running.  They won't be saved to disk automatically so they'll
>disappear at the end of the BATCH run.   You can use various functions
>(save(), save.image(), saveRDS(), writeLines(), etc.) to write them to
>disk if you don't want them to disappear.
>
>Duncan Murdoch
>
>
>>
>> THanking you,
>> yours sincerely,
>> AKSHAY M KULKARNI
>> 
>> *From:* Duncan Murdoch 
>> *Sent:* Saturday, March 18, 2023 11:49 PM
>> *To:* akshay kulkarni ; R help Mailing list
>> 
>> *Subject:* Re: [R] lexical scoping for scripts..
>> On 18/03/2023 1:57 p.m., akshay kulkarni wrote:
>>> Dear members,
>>>   The documentation for source() says:
>>>
>>> Input is read and parsed from that file until the end of the file is 
>>> reached, then the parsed expressions are evaluated sequentially in the 
>>> chosen environment.
>>>
>>> What does this mean? I presume that any objects that are CREATED by the 
>>> script are stored in the Global environment (if local = FALSE), but the 
>>> rules for lexical scoping are the same as for functions, right?
>>
>> No, assignments will happen in the "chosen environment" as well.
>>
>> I'm not sure exactly what you mean about the rules for lexical scoping,
>> but I think the answer is yes.  So if you do the following:
>>
>> Put this code in a file named "f.R":
>>
>> x <- 123
>> f <- function() x
>>
>> and you run this code in your global environment:
>>
>> x <- 456
>> e <- new.env()
>> source("f.R", local = e)
>>
>> Then you'll find that x retains the value 456, and e$f() returns 123.
>>
>>>
>>> Does the same apply for running the same script from the system command 
>>> line by R CMD BATCH?
>>
>> I don't think R CMD BATCH has any equivalent to the local argument.
>> Everything is evaluated in the global environment.
>>
>> Duncan Murdoch
>
>
>   [[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.

--
Sent from my phone. Please excuse my brevity.

[[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] lexical scoping for scripts......

2023-03-19 Thread akshay kulkarni
Dear Jeff,
Thanks a lot...

Thanking you,
Yours sincerely,
Akshay m kulkarni

From: Jeff Newmiller 
Sent: Monday, March 20, 2023 1:47 AM
To: akshay kulkarni ; r-help@r-project.org 
; Duncan Murdoch 
Subject: Re: [R] lexical scoping for scripts..

Again, the answer is "interactivity does not matter".

On March 19, 2023 12:54:28 PM PDT, akshay kulkarni  
wrote:
>Dear Jeff,
> I will not be running R command in the shell prompt. So there 
> is no banner, no > prompt. Just running "myscript.R" from the shell prompt. 
> or from crontab in Linux. I think you get the context.
>
>thanking you,
>yours sincerely
>AKSHAY M KULKARNI
>
>
>From: Jeff Newmiller 
>Sent: Monday, March 20, 2023 1:01 AM
>To: r-help@r-project.org ; akshay kulkarni 
>; Duncan Murdoch ; R help 
>Mailing list 
>Subject: Re: [R] lexical scoping for scripts..
>
>What do _you_ mean when you use the term "interactive"? Because R 
>distinguishes between executing code in a function and executing code from the 
>global environment, but it does not care whether a person is doing the typing 
>or not.
>
>I get the feeling that you think of your R code in terms of "scripts" when you 
>should be thinking of your code in terms of functions. What parameters do you 
>give to them, and what values do they return. Where you put those return 
>values is up to you... how do you save them now? (Depending on auto-saving to 
>.Rdata files is not a good idea in any case, but if you choose to use save() 
>to specific filename.Rdata files works the same whether you type it 
>interactively or use R CMD BATCH.
>
>On March 19, 2023 11:55:37 AM PDT, akshay kulkarni  
>wrote:
>>Dear Duncun,
>> What if there is no interactive "session" running? I 
>> will be running my scripts automatically from crontab in Linux.
>>
>>THanking you,
>>Yours sincerely,
>>AKSHAY M KULKARNI
>>
>>____
>>From: Duncan Murdoch 
>>Sent: Monday, March 20, 2023 12:20 AM
>>To: akshay kulkarni ; R help Mailing list 
>>
>>Subject: Re: [R] lexical scoping for scripts..
>>
>>On 19/03/2023 2:33 p.m., akshay kulkarni wrote:
>>> Dear Duncun,
>>>   thanks for the reply
>>>
>>> So when I run a script in the system command line by R CMD BATCH, the
>>> objects created in the script cannot be stored in the workspace ,right?
>>> If yes, how to save them? Moreover, the only way to save the objects
>>> CREATED from the script permanently is to save them to the disk, right?
>>
>>The objects you create *will* appear in the workspace of the session
>>that's running.  They won't be saved to disk automatically so they'll
>>disappear at the end of the BATCH run.   You can use various functions
>>(save(), save.image(), saveRDS(), writeLines(), etc.) to write them to
>>disk if you don't want them to disappear.
>>
>>Duncan Murdoch
>>
>>
>>>
>>> THanking you,
>>> yours sincerely,
>>> AKSHAY M KULKARNI
>>> 
>>> *From:* Duncan Murdoch 
>>> *Sent:* Saturday, March 18, 2023 11:49 PM
>>> *To:* akshay kulkarni ; R help Mailing list
>>> 
>>> *Subject:* Re: [R] lexical scoping for scripts..
>>> On 18/03/2023 1:57 p.m., akshay kulkarni wrote:
>>>> Dear members,
>>>>   The documentation for source() says:
>>>>
>>>> Input is read and parsed from that file until the end of the file is 
>>>> reached, then the parsed expressions are evaluated sequentially in the 
>>>> chosen environment.
>>>>
>>>> What does this mean? I presume that any objects that are CREATED by the 
>>>> script are stored in the Global environment (if local = FALSE), but the 
>>>> rules for lexical scoping are the same as for functions, right?
>>>
>>> No, assignments will happen in the "chosen environment" as well.
>>>
>>> I'm not sure exactly what you mean about the rules for lexical scoping,
>>> but I think the answer is yes.  So if you do the following:
>>>
>>> Put this code in a file named "f.R":
>>>
>>> x <- 123
>>> f <- function() x
>>>
>>> and you run this code in your global environment:
>>>
>>> x <- 456
>>> e <- new.env()
>>&g

[R] lexical scoping for scripts......

2023-03-18 Thread akshay kulkarni
Dear members,
 The documentation for source() says:

Input is read and parsed from that file until the end of the file is reached, 
then the parsed expressions are evaluated sequentially in the chosen 
environment.

What does this mean? I presume that any objects that are CREATED by the script 
are stored in the Global environment (if local = FALSE), but the rules for 
lexical scoping are the same as for functions, right?

Does the same apply for running the same script from the system command line by 
R CMD BATCH?

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] converting to date object...

2023-04-12 Thread akshay kulkarni
dear members,
I want to convert "12 APR 2023" into a Date object. 
I tried as_Date() from lubridate, but it is not working:

> as_date("12 APR 2023")
[1] NA
Warning message:
All formats failed to parse. No formats found.
> as_date("12-APR-2023")
[1] NA
Warning message:
All formats failed to parse. No formats found.

I am looking for a shorthand way of doing it. Of course, one can convert APR to 
4 and get the job done, but I ma looking for a short and elegant code

please help...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] converting to date object...

2023-04-12 Thread akshay kulkarni
Dear Dirk,
   Thaks a lot...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Dirk Eddelbuettel 
Sent: Wednesday, April 12, 2023 8:38 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] converting to date object...


That is what I wrote the anytime package for: effortless automatic
parsing.  Also works for dates:

   > library(anytime)
   > anydate("12 APR 2023")
   [1] "2023-04-12"
   >

Dirk

--
dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

[[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] aborting the execution of a script...

2023-04-12 Thread akshay kulkarni
Dear Duncan,
 But it is entirely different in my case...! As you 
said, the problem may be with my version of RStudio. The main point is that it 
doesn't pose any serious problems...

Thanks any way for your reply...

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Duncan Murdoch 
Sent: Wednesday, April 12, 2023 5:46 PM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] aborting the execution of a script...

This is what I get:

 > source("~/temp/test.R", echo = TRUE)

 > print(1)
[1] 1

 > stop("here")
Error in eval(ei, envir) : here

I get similar output in every variation I tried.  It never prints the 2.

On 12/04/2023 8:13 a.m., akshay kulkarni wrote:
> Dear Duncan,
>   What if I use source() with echo? I am using
> that in RStudio.
>
> THanking you,
> Yours sincerely
> AKSHAY M KULKARNI
> 
> *From:* Duncan Murdoch 
> *Sent:* Wednesday, April 12, 2023 5:35 PM
> *To:* akshay kulkarni ; R help Mailing list
> 
> *Subject:* Re: [R] aborting the execution of a script...
> On 12/04/2023 7:03 a.m., akshay kulkarni wrote:
>> Dear members,
>>  I have a script which I source it 
>> interactively. I have the following questions:
>>
>>
>>1.  If there is an error in an expression, an error message is printed, 
>> but the execution continues till the end of the script. I am sourcing with 
>> echo. Is there any way to abort the execution when the first error occurs? 
>> This happens with R CMD BATCH.  If there is an error midway, an error 
>> message is printed in the output
> file and the execution aborts. Is there a way to mimic this with source()?
>>2.  I am trying to abort the execution with ESC key, but again the same 
>> thing happens: it aborts the current expression but continues on. How to 
>> abort an R script with source()? I am using RStudio in windows.
>
> I don't see this behaviour.  If I put this in a script:
>
>print(1)
>stop("here")
>print(2)
>
> then execution stops at the "stop" line if I use source(), or R CMD
> BATCH , or in RStudio, Run or Source gives the same behaviour.  I
> think older versions of RStudio would have run all three lines using
> Run, but all the other methods have stopped at the stop() line.
>
> Duncan Murdoch
>
>
>


[[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] converting to date object...

2023-04-12 Thread akshay kulkarni
Hi Mark,
 Thanks a lot...

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Marc Schwartz 
Sent: Wednesday, April 12, 2023 8:33 PM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] converting to date object...

Hi,

You do not need to use third party packages for date or date/time objects in R.

If you review ?as.Date, you will see that there are two default formats for 
Date objects that are specified in the 'tryFormats' argument:

  tryFormats = c("%Y-%m-%d", "%Y/%m/%d")

If your date character vector does not conform to either one, which it does not 
in this case, then you need to explicitly specify the input format, the details 
of which are specified in ?strptime.

Thus:

> as.Date("12 APR 2023", format = "%d %b %Y")
[1] "2023-04-12"

> str(as.Date("12 APR 2023", format = "%d %b %Y"))
 Date[1:1], format: "2023-04-12"

> class(as.Date("12 APR 2023", format = "%d %b %Y"))
[1] "Date"

where the %d defines the day of the month number, %b defines the abbreviated 
month and %Y defines the four digit year. The spaces in between each specifier 
in the format argument reflect that there are spaces in the source vector, as 
opposed to hyphens (e.g. 12-APR-2023) or slashes (e.g. 12/APR/2023).

Note that once your vector is a Date class object, you can then manipulate them 
as dates and perform various operations on them. You can then use format() to 
alter the output format as you may need for other purposes, in which case, the 
formatted output is coerced back to a character vector, even though the 
internal storage is still a Date class object.

Regards,

Marc Schwartz



On April 12, 2023 at 10:34:26 AM, akshay kulkarni (akshay...@hotmail.com 
(mailto:akshay...@hotmail.com)) wrote:

> dear members,
> I want to convert "12 APR 2023" into a Date object. I tried as_Date() from 
> lubridate, but it is not working:
>
> > as_date("12 APR 2023")
> [1] NA
> Warning message:
> All formats failed to parse. No formats found.
> > as_date("12-APR-2023")
> [1] NA
> Warning message:
> All formats failed to parse. No formats found.
>
> I am looking for a shorthand way of doing it. Of course, one can convert APR 
> to 4 and get the job done, but I ma looking for a short and elegant code
>
> please help...
>
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
>
> [[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.


Re: [R] converting to date object...

2023-04-12 Thread akshay kulkarni
Hi Eric,
  THanks a lot..

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Eric Berger 
Sent: Wednesday, April 12, 2023 8:20 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] converting to date object...

lubridate::dmy("12 APR 2023")


On Wed, Apr 12, 2023 at 5:34 PM akshay kulkarni 
mailto:akshay...@hotmail.com>> wrote:
dear members,
I want to convert "12 APR 2023" into a Date object. 
I tried as_Date() from lubridate, but it is not working:

> as_date("12 APR 2023")
[1] NA
Warning message:
All formats failed to parse. No formats found.
> as_date("12-APR-2023")
[1] NA
Warning message:
All formats failed to parse. No formats found.

I am looking for a shorthand way of doing it. Of course, one can convert APR to 
4 and get the job done, but I ma looking for a short and elegant code

please help...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] converting a character matrix into numeric....

2023-04-12 Thread akshay kulkarni
Dear Rui,
 Not working. I have entirely removed the column containing % 
but am still bootless:

> head(coredata(INFYTX))
 INFY Historical Data INFY Historical Data INFY Historical Data INFY 
Historical Data
[1,] "47.26"  "44.28"  "47.56"  "44.28"
[2,] "46.30"  "44.92"  "46.53"  "44.06"
[3,] "45.82"  "47.27"  "47.50"  "45.63"
[4,] "45.62"  "46.06"  "46.16"  "44.73"
[5,] "45.05"  "46.28"  "46.50"  "44.77"
[6,] "45.28"  "44.80"  "46.84"  "44.53"
 INFY Historical Data
[1,] "1805267"
[2,] "1536300"
[3,] "887774"
[4,] "944036"
[5,] "759898"
[6,] "1185402"
> class(coredata(INFYTX)) <- "numeric"
> head(coredata(INFYTX))
 INFY Historical Data INFY Historical Data INFY Historical Data INFY 
Historical Data
[1,] "47.26"  "44.28"  "47.56"  "44.28"
[2,] "46.3"   "44.92"  "46.53"  "44.06"
[3,] "45.82"  "47.27"  "47.5"   "45.63"
[4,] "45.62"  "46.06"  "46.16"  "44.73"
[5,] "45.05"  "46.28"      "46.5"   "44.77"
[6,] "45.28"  "44.8"   "46.84"  "44.53"
 INFY Historical Data
[1,] "1805267"
[2,] "1536300"
[3,] "887774"
[4,] "944036"
[5,] "759898"
[6,] "1185402"

THanking you,
Yours sincerely,
AKSHAY M KULKARNI


From: Rui Barradas 
Sent: Thursday, April 13, 2023 12:46 AM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] converting a character matrix into numeric

�s 19:57 de 12/04/2023, akshay kulkarni escreveu:
> Dear members,
>  I have an xts object:
>
>> head(INFYTX)
> INFY Historical Data INFY Historical Data.1 INFY Historical Data.2
> 2003-04-16 "47.26"  "44.28""47.56"
> 2003-04-17 "46.30"  "44.92""46.53"
> 2003-04-21 "45.82"  "47.27""47.50"
> 2003-04-22 "45.62"  "46.06""46.16"
> 2003-04-23 "45.05"  "46.28""46.50"
> 2003-04-24 "45.28"  "44.80""46.84"
> INFY Historical Data.3 INFY Historical Data.4
> 2003-04-16 "44.28""1805267"  "5.77%"
> 2003-04-17 "44.06""1536300"  "-2.03%"
> 2003-04-21 "45.63""887774"   "-1.04%"
> 2003-04-22 "44.73""944036"   "-0.44%"
> 2003-04-23 "44.77""759898"   "-1.25%"
> 2003-04-24 "44.53""1185402"  "0.51%"
>
> But it is populated with character values and I want to convert them to 
> numeric. THe following code doesn't work:
>
>> head(coredata(INFYTX))
>   INFY Historical Data INFY Historical Data.1 INFY Historical Data.2 INFY 
> Historical Data.3
> [1,] "47.26"  "44.28""47.56"
> "44.28"
> [2,] "46.30"  "44.92""46.53"
> "44.06"
> [3,] "45.82"  "47.27""47.50"
> "45.63"
> [4,] "45.62"  "46.06""46.16"
> "44.73"
> [5,] "45.05"  "46.28""46.50"
> "44.77"
> [6,] "45.28"  "44.80""46.84"
> "44.53"
>   INFY Historical Data.4
> [1,] "18

Re: [R] converting a character matrix into numeric....

2023-04-12 Thread akshay kulkarni
Dear Jeff,
 Regrets for not trying that before...never knew that % was the 
culprit...!

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Jeff Newmiller 
Sent: Thursday, April 13, 2023 1:08 AM
To: r-help@r-project.org ; akshay kulkarni 
; Rui Barradas ; R help Mailing 
list 
Subject: Re: [R] converting a character matrix into numeric

Isn't this like trying to tie up the horse after it has left the barn? Why not 
figure all this out _before_ converting to xts?

On April 12, 2023 12:29:49 PM PDT, akshay kulkarni  
wrote:
>Dear Rui,
> Not working. I have entirely removed the column containing % 
> but am still bootless:
>
>> head(coredata(INFYTX))
> INFY Historical Data INFY Historical Data INFY Historical Data INFY 
> Historical Data
>[1,] "47.26"  "44.28"  "47.56"  "44.28"
>[2,] "46.30"  "44.92"  "46.53"  "44.06"
>[3,] "45.82"  "47.27"  "47.50"  "45.63"
>[4,] "45.62"  "46.06"  "46.16"  "44.73"
>[5,] "45.05"  "46.28"  "46.50"  "44.77"
>[6,] "45.28"  "44.80"  "46.84"  "44.53"
> INFY Historical Data
>[1,] "1805267"
>[2,] "1536300"
>[3,] "887774"
>[4,] "944036"
>[5,] "759898"
>[6,] "1185402"
>> class(coredata(INFYTX)) <- "numeric"
>> head(coredata(INFYTX))
> INFY Historical Data INFY Historical Data INFY Historical Data INFY 
> Historical Data
>[1,] "47.26"  "44.28"  "47.56"  "44.28"
>[2,] "46.3"   "44.92"  "46.53"  "44.06"
>[3,] "45.82"  "47.27"  "47.5"   "45.63"
>[4,] "45.62"  "46.06"  "46.16"  "44.73"
>[5,] "45.05"  "46.28"  "46.5"   "44.77"
>[6,] "45.28"  "44.8"   "46.84"  "44.53"
> INFY Historical Data
>[1,] "1805267"
>[2,] "1536300"
>[3,] "887774"
>[4,] "944036"
>[5,] "759898"
>[6,] "1185402"
>
>THanking you,
>Yours sincerely,
>AKSHAY M KULKARNI
>
>
>From: Rui Barradas 
>Sent: Thursday, April 13, 2023 12:46 AM
>To: akshay kulkarni ; R help Mailing list 
>
>Subject: Re: [R] converting a character matrix into numeric
>
>�s 19:57 de 12/04/2023, akshay kulkarni escreveu:
>> Dear members,
>>  I have an xts object:
>>
>>> head(INFYTX)
>> INFY Historical Data INFY Historical Data.1 INFY Historical 
>> Data.2
>> 2003-04-16 "47.26"  "44.28""47.56"
>> 2003-04-17 "46.30"  "44.92""46.53"
>> 2003-04-21 "45.82"  "47.27""47.50"
>> 2003-04-22 "45.62"  "46.06""46.16"
>> 2003-04-23 "45.05"  "46.28""46.50"
>> 2003-04-24 "45.28"  "44.80""46.84"
>> INFY Historical Data.3 INFY Historical Data.4
>> 2003-04-16 "44.28""1805267"  "5.77%"
>> 2003-04-17 "44.06""1536300"  "-2.03%"
>> 2003-04-21 "45.63""887774"   "-1.04%"
>> 2003-04-22 "44.73""944036"   "-0.44%"
>> 2003-04-23 "44.77""759898"   "-1.25%"
>> 2003-04-24 "44.53""1185402"  "0.51%"
>>
>> But it is populated with character values and I want to convert them to 
>> numeric. THe following code doesn't work:
>>
>>> head(coredata(INFYTX))
>>   INFY Historical Data INFY 

[R] converting a character matrix into numeric....

2023-04-12 Thread akshay kulkarni
Dear members,
I have an xts object:

> head(INFYTX)
   INFY Historical Data INFY Historical Data.1 INFY Historical Data.2
2003-04-16 "47.26"  "44.28""47.56"
2003-04-17 "46.30"  "44.92""46.53"
2003-04-21 "45.82"  "47.27""47.50"
2003-04-22 "45.62"  "46.06""46.16"
2003-04-23 "45.05"  "46.28""46.50"
2003-04-24 "45.28"  "44.80""46.84"
   INFY Historical Data.3 INFY Historical Data.4
2003-04-16 "44.28""1805267"  "5.77%"
2003-04-17 "44.06""1536300"  "-2.03%"
2003-04-21 "45.63""887774"   "-1.04%"
2003-04-22 "44.73""944036"   "-0.44%"
2003-04-23 "44.77""759898"   "-1.25%"
2003-04-24 "44.53""1185402"  "0.51%"

But it is populated with character values and I want to convert them to 
numeric. THe following code doesn't work:

> head(coredata(INFYTX))
 INFY Historical Data INFY Historical Data.1 INFY Historical Data.2 INFY 
Historical Data.3
[1,] "47.26"  "44.28""47.56""44.28"
[2,] "46.30"  "44.92""46.53""44.06"
[3,] "45.82"  "47.27""47.50""45.63"
[4,] "45.62"  "46.06""46.16""44.73"
[5,] "45.05"  "46.28""46.50""44.77"
[6,] "45.28"  "44.80""46.84""44.53"
 INFY Historical Data.4
[1,] "1805267"  "5.77%"
[2,] "1536300"  "-2.03%"
[3,] "887774"   "-1.04%"
[4,] "944036"   "-0.44%"
[5,] "759898"   "-1.25%"
[6,] "1185402"  "0.51%"

> class(coredata(INFYTX))
[1] "matrix" "array"
> class(coredata(INFYTX)) <- "numeric"
Warning message:
In class(coredata(INFYTX)) <- "numeric" : NAs introduced by coercion
> class(coredata(INFYTX))
[1] "matrix" "array"
> head(coredata(INFYTX))
 INFY Historical Data INFY Historical Data.1 INFY Historical Data.2 INFY 
Historical Data.3
[1,] "47.26"  "44.28""47.56""44.28"
[2,] "46.3"   "44.92""46.53""44.06"
[3,] "45.82"  "47.27""47.5" "45.63"
[4,] "45.62"  "46.06""46.16""44.73"
[5,] "45.05"  "46.28""46.5" "44.77"
[6,] "45.28"  "44.8" "46.84""44.53"
 INFY Historical Data.4
[1,] "1805267"  NA
[2,] "1536300"  NA
[3,] "887774"   NA
[4,] "944036"   NA
[5,] "759898"   NA
[6,] "1185402"  NA

Why is the coredata matrix not changing to numeric when the class is changed to 
numeric? How else to convert coredata into numeric?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] problem in arfima in forecast...

2023-04-25 Thread akshay kulkarni
Dear members,
 I am using the forecast package for arfima 
modelling. THe following is the code:

> arfima(ygrpch(OHLCDataEP[[1]]))

Call:
  arfima(y = ygrpch(OHLCDataEP[[1]]))

*** Warning during (fdcov) fit: unable to compute correlation matrix; maybe 
change 'h'

Coefficients:
dma.ma1
0.1745253 0.1600765
sigma[eps] = 34.4493
a list with components:
 [1] "log.likelihood"  "n"   "msg" "d"   
"ar"
 [6] "ma"  "covariance.dpq"  "fnormMin""sigma"   
"stderror.dpq"
[11] "correlation.dpq" "h"   "d.tol"   "M"   
"hessian.dpq"
[16] "length.w""residuals"   "fitted"  "call""x"
[21] "series"

What does the warning say? Is it Ok to proceed with it if the correlation 
matrix can't be caclulated? I just want the prediction, and forecast() is 
working fine:

> forecast(arfima(ygrpch(OHLCDataEP[[1]])), h = 1)
Point Forecast Lo 80Hi 80 Lo 95Hi 95
188   26.01569 -17.96402 69.99539 -41.24547 93.27684

I just want the point forecast. Is there any problem with arfima() as I am 
using it?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] AIc and BIC in caret...

2023-04-19 Thread akshay kulkarni
Dear members,
 I am doing some modelling with caret package in R. I 
do suppose that the package doesn't consider AIC and BIC for model selection, 
right? They penalise the number of prameters, but I am ready to spend a little 
more time and a little more money to run the model with more number of 
parameters, but with a very less SSE.

I know that AIC and BIC are not meant for non parametric ML models, but just 
want to confirm

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] AIc and BIC in caret...

2023-04-19 Thread akshay kulkarni
Dear Jeff,
Thanks for the rpely. I will definitely have a look at the wiki 
link.

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Jeff Newmiller 
Sent: Wednesday, April 19, 2023 8:10 PM
To: r-help@r-project.org ; akshay kulkarni 
; R help Mailing list 
Subject: Re: [R] AIc and BIC in caret...

This is a statistical question, not actually a question about R, and thus not 
on topic. Using too many variables leads to models that tend to have large 
errors on new data (not from your fitting sample). [1]

[1] https://en.m.wikipedia.org/wiki/Overfitting

On April 19, 2023 6:50:44 AM PDT, akshay kulkarni  wrote:
>Dear members,
> I am doing some modelling with caret package in R. I 
> do suppose that the package doesn't consider AIC and BIC for model selection, 
> right? They penalise the number of prameters, but I am ready to spend a 
> little more time and a little more money to run the model with more number of 
> parameters, but with a very less SSE.
>
>I know that AIC and BIC are not meant for non parametric ML models, but just 
>want to confirm
>
>Thanking you,
>Yours sincerely,
>AKSHAY M KULKARNI
>
>   [[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.

--
Sent from my phone. Please excuse my brevity.

[[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] AIc and BIC in caret...

2023-04-19 Thread akshay kulkarni
Dear Tim,
THanks a lot

THanking you,
Yours sincerely,
AKSHAY M KULKARNI


From: Ebert,Timothy Aaron 
Sent: Wednesday, April 19, 2023 10:59 PM
To: Jeff Newmiller ; r-help@r-project.org 
; akshay kulkarni ; R help Mailing 
list 
Subject: RE: [R] AIc and BIC in caret...

I searched for "caret AIC package r" and found this: 
https://stats.stackexchange.com/questions/443286/r-interpreting-output-of-carettrain-with-method-glmstepaic
My guess (without having used it) is that this uses AIC in a stepwise model 
building approach.

-Original Message-
From: R-help  On Behalf Of Jeff Newmiller
Sent: Wednesday, April 19, 2023 10:41 AM
To: r-help@r-project.org; akshay kulkarni ; R help 
Mailing list 
Subject: Re: [R] AIc and BIC in caret...

[External Email]

This is a statistical question, not actually a question about R, and thus not 
on topic. Using too many variables leads to models that tend to have large 
errors on new data (not from your fitting sample). [1]

[1] https://en.m.wikipedia.org/wiki/Overfitting

On April 19, 2023 6:50:44 AM PDT, akshay kulkarni  wrote:
>Dear members,
> I am doing some modelling with caret package in R. I 
> do suppose that the package doesn't consider AIC and BIC for model selection, 
> right? They penalise the number of prameters, but I am ready to spend a 
> little more time and a little more money to run the model with more number of 
> parameters, but with a very less SSE.
>
>I know that AIC and BIC are not meant for non parametric ML models, but just 
>want to confirm
>
>Thanking you,
>Yours sincerely,
>AKSHAY M KULKARNI
>
>   [[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.

--
Sent from my phone. Please excuse my brevity.

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


[R] running a function repeatedly on error....

2023-04-19 Thread akshay kulkarni
Dear members,
  I have a function FUN1 that downloads some data from 
the internet. It so happens that the function doesn't work the first time, but 
on the second or third attempt it works. I want to run the function repeatedly 
for four times if it throws an error:

X <- tryCatch(FUN1, error = function(c) {FUN1})

This runs the function two times. But I want to run the function four times if 
throws an error, but on the fifth attempt if it throws an error, abort. I know 
I can include the tryCatch call inside FUN1 and call it, but any short and 
elegant code to that effect?

Thanking you,
Yours sincerely
AKSHAY M KULKARNI



[[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] running a function repeatedly on error....

2023-04-19 Thread akshay kulkarni
Dear Iris,
THanks a lot...

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Iris Simmons 
Sent: Wednesday, April 19, 2023 11:22 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] running a function repeatedly on error

I might try something like this:

FUN1 <- function ()
{
threshold <- 4L
fails <- 0L
internal <- function() {
## do the actual downloading here
tryCatch({
download.file(<...>)
}, error = function() {
fails <<- fails + 1L
if (fails >= threshold) stop("unable to download file(s)")
internal()
})
}
internal()
}

which should attempt to download the files, stopping after 4 failed 
attempt[[elided Hotmail spam]]

On Wed, Apr 19, 2023, 12:57 akshay kulkarni 
mailto:akshay...@hotmail.com>> wrote:
Dear members,
  I have a function FUN1 that downloads some data from 
the internet. It so happens that the function doesn't work the first time, but 
on the second or third attempt it works. I want to run the function repeatedly 
for four times if it throws an error:

X <- tryCatch(FUN1, error = function(c) {FUN1})

This runs the function two times. But I want to run the function four times if 
throws an error, but on the fifth attempt if it throws an error, abort. I know 
I can include the tryCatch call inside FUN1 and call it, but any short and 
elegant code to that effect?

Thanking you,
Yours sincerely
AKSHAY M KULKARNI



[[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] extracting pdf tables...

2023-04-09 Thread akshay kulkarni
Dear Jeff,
  Thanks for your reply.

I have the following:

> colnames(IDT[[4]])
[1] "X168""TATA.MOTORS.LIMITED" "TATAMOTORS"  "X4"

THe above has to be the first row of IDT[[4]]. The first row is getting parsed 
as the column name. How do you make that the first row of IDT[[4]]?

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Jeff Newmiller 
Sent: Monday, April 10, 2023 12:27 AM
To: akshay kulkarni ; r-help@r-project.org 

Subject: Re: [R] extracting pdf tables...

Your code used cbind. My first answer was appropriate for rbind.

So you still need to figure out how to deal with the different columns in the 
tables, which requires more knowledge about their contents than we have.

On April 9, 2023 11:43:01 AM PDT, akshay kulkarni  wrote:
>Dear Jeff,
>  I want to rbind.
>
>Thanking you,
>Yours sincerely,
>AKSHAY M KULKARNI
>
>From: R-help  on behalf of Jeff Newmiller 
>
>Sent: Sunday, April 9, 2023 11:57 PM
>To: r-help@r-project.org 
>Subject: Re: [R] extracting pdf tables...
>
>Sorry, did not read closely enough.
>
>Did you want rbind (which has no problem with different numbers of rows) or 
>merge (which requires that there be key columns that can be aligned by 
>repeating data)?
>
>On April 9, 2023 10:49:09 AM PDT, Jeff Newmiller  
>wrote:
>>Clearly the column names are different. You need to decide what to do about 
>>that. Choose the subset of dataframes where the column names are the same? 
>>Rename columns? Omit some columns? Add missing columns filled with NA?
>>
>>On April 9, 2023 10:22:32 AM PDT, akshay kulkarni  
>>wrote:
>>>Dear members,
>>> I am extracting a pdf table by the following 
>>> code:
>>>
>>>> library(tabulizer)
>>>> IDT <- 
>>>> extract_tables("https://www.canmoney.in/pdf/INTRADAYLEVERAGE-20220531-latest.pdf",output
>>>>  = "data.frame")
>>>
>>>It returns 4 different data frames which I want to combine them and make one 
>>>data frame. But when I run this:
>>>
>>>> rbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]])
>>> Error in match.names(clabs, names(xi)) :
>>>names do not match previous names
>>>
>>>Also:
>>>
>>>> class(IDT[[1]])
>>>[1] "data.frame"
>>>
>>>> cbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]],make.row.names = FALSE)
>>> Error in data.frame(..., check.names = FALSE) :
>>>arguments imply differing number of rows: 55, 56, 30, 1
>>>
>>>Can anyone please help me to combine all these 4 different data frames?
>>>
>>>Thanking you,
>>>Yours sincerely,
>>>AKSHAY M KULKARNI
>>>
>>>  [[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.
>>
>
>--
>Sent from my phone. Please excuse my brevity.
>
>__
>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.

--
Sent from my phone. Please excuse my brevity.

[[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] extracting pdf tables...

2023-04-09 Thread akshay kulkarni
Dear Jeff,
  I want to rbind.

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: R-help  on behalf of Jeff Newmiller 

Sent: Sunday, April 9, 2023 11:57 PM
To: r-help@r-project.org 
Subject: Re: [R] extracting pdf tables...

Sorry, did not read closely enough.

Did you want rbind (which has no problem with different numbers of rows) or 
merge (which requires that there be key columns that can be aligned by 
repeating data)?

On April 9, 2023 10:49:09 AM PDT, Jeff Newmiller  
wrote:
>Clearly the column names are different. You need to decide what to do about 
>that. Choose the subset of dataframes where the column names are the same? 
>Rename columns? Omit some columns? Add missing columns filled with NA?
>
>On April 9, 2023 10:22:32 AM PDT, akshay kulkarni  
>wrote:
>>Dear members,
>> I am extracting a pdf table by the following 
>> code:
>>
>>> library(tabulizer)
>>> IDT <- 
>>> extract_tables("https://www.canmoney.in/pdf/INTRADAYLEVERAGE-20220531-latest.pdf",output
>>>  = "data.frame")
>>
>>It returns 4 different data frames which I want to combine them and make one 
>>data frame. But when I run this:
>>
>>> rbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]])
>> Error in match.names(clabs, names(xi)) :
>>names do not match previous names
>>
>>Also:
>>
>>> class(IDT[[1]])
>>[1] "data.frame"
>>
>>> cbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]],make.row.names = FALSE)
>> Error in data.frame(..., check.names = FALSE) :
>>arguments imply differing number of rows: 55, 56, 30, 1
>>
>>Can anyone please help me to combine all these 4 different data frames?
>>
>>Thanking you,
>>Yours sincerely,
>>AKSHAY M KULKARNI
>>
>>  [[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.
>

--
Sent from my phone. Please excuse my brevity.

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


[R] extracting pdf tables...

2023-04-09 Thread akshay kulkarni
Dear members,
 I am extracting a pdf table by the following code:

> library(tabulizer)
> IDT <- 
> extract_tables("https://www.canmoney.in/pdf/INTRADAYLEVERAGE-20220531-latest.pdf",output
>  = "data.frame")

It returns 4 different data frames which I want to combine them and make one 
data frame. But when I run this:

> rbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]])
 Error in match.names(clabs, names(xi)) :
names do not match previous names

Also:

> class(IDT[[1]])
[1] "data.frame"

> cbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]],make.row.names = FALSE)
 Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 55, 56, 30, 1

Can anyone please help me to combine all these 4 different data frames?

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] can't install nser...

2023-04-09 Thread akshay kulkarni
Dear Andrew,
 Thanks its working...

Thanking you,
Yours sincerely
AKSHAY M KULKARNI

From: Andrew Simmons 
Sent: Monday, April 10, 2023 3:36 AM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] can't install nser...

It says that nser requires the most recent version of magrittr that you do not 
have installed. You must update magrittr before attempting to install nser:

update.packages(oldPkgs = "magrittr")

or at the prompt you were presented before, choose to update magrittr before 
installing nser.

On Sun, Apr 9, 2023, 17:55 akshay kulkarni 
mailto:akshay...@hotmail.com>> wrote:
Dear members,
 I can't install "nser" package. It is not in cran 
but install_version and install_github both are not working:

> install_version("nser",version = "1.4.0")
Downloading package from url: 
https://cran.rstudio.com//src/contrib/Archive/nser/nser_1.4.0.tar.gz
These packages have more recent versions available.
It is recommended to update all of them.
Which would you like to update?

 1: All
 2: CRAN packages only
 3: None
 4: rlang(1.0.4 -> 1.1.0 ) [CRAN]
 5: cli  (3.3.0 -> 3.6.1 ) [CRAN]
 6: openssl  (1.4.5 -> 2.0.6 ) [CRAN]
 7: curl (4.3.2 -> 5.0.0 ) [CRAN]
 8: Rcpp (1.0.7 -> 1.0.10) [CRAN]
 9: ps   (1.6.0 -> 1.7.4 ) [CRAN]
10: processx (3.5.2 -> 3.8.0 ) [CRAN]
11: purrr(0.3.4 -> 1.0.1 ) [CRAN]
12: magrittr (2.0.1 -> 2.0.3 ) [CRAN]
13: fastmap  (1.1.0 -> 1.1.1 ) [CRAN]
14: cachem   (1.0.6 -> 1.0.7 ) [CRAN]
15: fs   (1.5.2 -> 1.6.1 ) [CRAN]

Enter one or more numbers, or an empty line to skip updates:
* installing *source* package 'nser' ...
** package 'nser' successfully unpacked and MD5 sums checked
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = 
vI[[j]]) :
  namespace 'magrittr' 2.0.1 is being loaded, but >= 2.0.3 is required
Calls:  ... namespaceImportFrom -> asNamespace -> loadNamespace
Execution halted
ERROR: lazy loading failed for package 'nser'
* removing 'C:/Program Files/R/R-4.1.2/library/nser'
Warning message:
In i.p(...) :
  installation of package 
�C:/Users/ADMINI~1/AppData/Local/Temp/2/RtmpktmxP2/remotesbec536a2c/nser� had 
non-zero exit status


Can you please help?

Thanking you,
Yours sincerely,
AKSHAY M MKULKARNI

[[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] extracting pdf tables...

2023-04-09 Thread akshay kulkarni
Dear Jeff,
  Got the answer...I changed output = "matrix" in extract_table 
and used as.data.frame to coerce the output matrix to a data frame and
rbind is working fine then...

Thanks anyways for your reply...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Jeff Newmiller 
Sent: Monday, April 10, 2023 12:53 AM
To: akshay kulkarni ; r-help@r-project.org 

Subject: Re: [R] extracting pdf tables...

I don't know... I have never used tabulizer (which is no longer on CRAN anyway).

In general you would provide an argument to the data import function that would 
tell it to expect a header. I suspect you will have to set the names(IDT[[4]]) 
<- whatever it should be and remove the first row from the data frame.

On April 9, 2023 12:03:36 PM PDT, akshay kulkarni  wrote:
>Dear Jeff,
>  Thanks for your reply.
>
>I have the following:
>
>> colnames(IDT[[4]])
>[1] "X168""TATA.MOTORS.LIMITED" "TATAMOTORS"  "X4"
>
>THe above has to be the first row of IDT[[4]]. The first row is getting parsed 
>as the column name. How do you make that the first row of IDT[[4]]?
>
>Thanking you,
>Yours sincerely,
>AKSHAY M KULKARNI
>____
>From: Jeff Newmiller 
>Sent: Monday, April 10, 2023 12:27 AM
>To: akshay kulkarni ; r-help@r-project.org 
>
>Subject: Re: [R] extracting pdf tables...
>
>Your code used cbind. My first answer was appropriate for rbind.
>
>So you still need to figure out how to deal with the different columns in the 
>tables, which requires more knowledge about their contents than we have.
>
>On April 9, 2023 11:43:01 AM PDT, akshay kulkarni  
>wrote:
>>Dear Jeff,
>>  I want to rbind.
>>
>>Thanking you,
>>Yours sincerely,
>>AKSHAY M KULKARNI
>>
>>From: R-help  on behalf of Jeff Newmiller 
>>
>>Sent: Sunday, April 9, 2023 11:57 PM
>>To: r-help@r-project.org 
>>Subject: Re: [R] extracting pdf tables...
>>
>>Sorry, did not read closely enough.
>>
>>Did you want rbind (which has no problem with different numbers of rows) or 
>>merge (which requires that there be key columns that can be aligned by 
>>repeating data)?
>>
>>On April 9, 2023 10:49:09 AM PDT, Jeff Newmiller  
>>wrote:
>>>Clearly the column names are different. You need to decide what to do about 
>>>that. Choose the subset of dataframes where the column names are the same? 
>>>Rename columns? Omit some columns? Add missing columns filled with NA?
>>>
>>>On April 9, 2023 10:22:32 AM PDT, akshay kulkarni  
>>>wrote:
>>>>Dear members,
>>>> I am extracting a pdf table by the following 
>>>> code:
>>>>
>>>>> library(tabulizer)
>>>>> IDT <- 
>>>>> extract_tables("https://www.canmoney.in/pdf/INTRADAYLEVERAGE-20220531-latest.pdf",output
>>>>>  = "data.frame")
>>>>
>>>>It returns 4 different data frames which I want to combine them and make 
>>>>one data frame. But when I run this:
>>>>
>>>>> rbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]])
>>>> Error in match.names(clabs, names(xi)) :
>>>>names do not match previous names
>>>>
>>>>Also:
>>>>
>>>>> class(IDT[[1]])
>>>>[1] "data.frame"
>>>>
>>>>> cbind(IDT[[1]],IDT[[2]],IDT[[3]],IDT[[4]],make.row.names = FALSE)
>>>> Error in data.frame(..., check.names = FALSE) :
>>>>arguments imply differing number of rows: 55, 56, 30, 1
>>>>
>>>>Can anyone please help me to combine all these 4 different data frames?
>>>>
>>>>Thanking you,
>>>>Yours sincerely,
>>>>AKSHAY M KULKARNI
>>>>
>>>>  [[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.
>>>
>>
>>--
>>Sent from my phone. Please excuse my brevity.
>>
>>__
>>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.
>
>--
>Sent from my phone. Please excuse my brevity.

--
Sent from my phone. Please excuse my brevity.

[[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] can't install nser...

2023-04-09 Thread akshay kulkarni
Dear members,
 I can't install "nser" package. It is not in cran 
but install_version and install_github both are not working:

> install_version("nser",version = "1.4.0")
Downloading package from url: 
https://cran.rstudio.com//src/contrib/Archive/nser/nser_1.4.0.tar.gz
These packages have more recent versions available.
It is recommended to update all of them.
Which would you like to update?

 1: All
 2: CRAN packages only
 3: None
 4: rlang(1.0.4 -> 1.1.0 ) [CRAN]
 5: cli  (3.3.0 -> 3.6.1 ) [CRAN]
 6: openssl  (1.4.5 -> 2.0.6 ) [CRAN]
 7: curl (4.3.2 -> 5.0.0 ) [CRAN]
 8: Rcpp (1.0.7 -> 1.0.10) [CRAN]
 9: ps   (1.6.0 -> 1.7.4 ) [CRAN]
10: processx (3.5.2 -> 3.8.0 ) [CRAN]
11: purrr(0.3.4 -> 1.0.1 ) [CRAN]
12: magrittr (2.0.1 -> 2.0.3 ) [CRAN]
13: fastmap  (1.1.0 -> 1.1.1 ) [CRAN]
14: cachem   (1.0.6 -> 1.0.7 ) [CRAN]
15: fs   (1.5.2 -> 1.6.1 ) [CRAN]

Enter one or more numbers, or an empty line to skip updates:
* installing *source* package 'nser' ...
** package 'nser' successfully unpacked and MD5 sums checked
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = 
vI[[j]]) :
  namespace 'magrittr' 2.0.1 is being loaded, but >= 2.0.3 is required
Calls:  ... namespaceImportFrom -> asNamespace -> loadNamespace
Execution halted
ERROR: lazy loading failed for package 'nser'
* removing 'C:/Program Files/R/R-4.1.2/library/nser'
Warning message:
In i.p(...) :
  installation of package 
�C:/Users/ADMINI~1/AppData/Local/Temp/2/RtmpktmxP2/remotesbec536a2c/nser� had 
non-zero exit status


Can you please help?

Thanking you,
Yours sincerely,
AKSHAY M MKULKARNI

[[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] aborting the execution of a script...

2023-04-12 Thread akshay kulkarni
Dear members,
I have a script which I source it interactively. I 
have the following questions:


  1.  If there is an error in an expression, an error message is printed, but 
the execution continues till the end of the script. I am sourcing with echo. Is 
there any way to abort the execution when the first error occurs? This happens 
with R CMD BATCH. If there is an error midway, an error message is printed in 
the output file and the execution aborts. Is there a way to mimic this with 
source()?
  2.  I am trying to abort the execution with ESC key, but again the same thing 
happens: it aborts the current expression but continues on. How to abort an R 
script with source()? I am using RStudio in windows.

Please help,

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] on lexical scoping....

2023-04-05 Thread akshay kulkarni
Dear richard,
Bulls eye! thanks for your pointed reply...!

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Richard O'Keefe 
Sent: Wednesday, April 5, 2023 10:30 AM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] on lexical scoping

R *does* search the environment stack.

> search()
[1] ".GlobalEnv""package:stats" "package:graphics"
[4] "package:grDevices" "package:utils" "package:datasets"
[7] "package:methods"   "Autoloads" "package:base

What you seem to be missing is that a package may contain
bindings that it does not export, as the wording of this
error message reminds us:
> utils::y
Error: 'y' is not an exported object from 'namespace:utils'

So when package/namespace goes onto the environment stack,
it's only the *exported* bindings that become visible.



On Wed, 5 Apr 2023 at 01:56, akshay kulkarni 
mailto:akshay...@hotmail.com>> wrote:
Dear Members,
 I have the following code typed at the console 
prompt:

y   <-   x*10

X has not been defined and the above code throws an object not found error. 
That is, the global environment does not contain x. Why doesn't it look further 
in the environment stack, like that of packages? There are thousands of 
packages that contain the variable named  x. Of course, that happens if the 
above code is in a function (or does it?).

What concept of R is at work in this dichotomy?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] on lexical scoping....

2023-04-05 Thread akshay kulkarni
dear Bert,
  I could predict most of them, but,of course, you have not 
wasted my time!

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Bert Gunter 
Sent: Wednesday, April 5, 2023 4:36 AM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] on lexical scoping

The following *might* be of use to you. If you can predict what the various 
function invocations will do, I think you have a reasonable grasp of how 
lexical scoping works in R (contrary or supplementary opinions welcome).  It is 
the sort of thing you will find in the references also. If this is all obvious, 
sorry for wasting your time.
###
search()
ls()
dat <- list(x =2)
attach(dat,2)
search()
f <- function(){
   g <- function() x
   x <- 3
   g}
h <- f()
g <- function()x
ls()
h()
g()
detach(dat)
h()
g()

##
## Here is what this gives starting with an empty .GlobalEnv.
##

> search()
 [1] ".GlobalEnv""package:tools" "package:lattice"   "tools:rstudio"
 [5] "package:stats" "package:graphics"  "package:grDevices" "package:utils"
 [9] "package:datasets"  "package:methods"   "Autoloads" "package:base"
> ls()
character(0)
> dat <- list(x =2)
> attach(dat,2)
> search()
 [1] ".GlobalEnv""dat"   "package:tools" 
"package:lattice"
 [5] "tools:rstudio" "package:stats" "package:graphics"  
"package:grDevices"
 [9] "package:utils" "package:datasets"  "package:methods"   "Autoloads"
[13] "package:base"
> f <- function(){
+g <- function() x
+x <- 3
+g}
> h <- f()
> g <- function()x
> ls()
[1] "dat" "f"   "g"   "h"
> h()
[1] 3
> g()
[1] 2
> detach(dat)
> h()
[1] 3
> g()
Error in g() : object 'x' not found

-- Bert


On Tue, Apr 4, 2023 at 6:56 AM akshay kulkarni 
mailto:akshay...@hotmail.com>> wrote:
Dear Members,
 I have the following code typed at the console 
prompt:

y   <-   x*10

X has not been defined and the above code throws an object not found error. 
That is, the global environment does not contain x. Why doesn't it look further 
in the environment stack, like that of packages? There are thousands of 
packages that contain the variable named  x. Of course, that happens if the 
above code is in a function (or does it?).

What concept of R is at work in this dichotomy?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

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


[R] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Members,
 I have the following code typed at the console 
prompt:

y   <-   x*10

X has not been defined and the above code throws an object not found error. 
That is, the global environment does not contain x. Why doesn't it look further 
in the environment stack, like that of packages? There are thousands of 
packages that contain the variable named  x. Of course, that happens if the 
above code is in a function (or does it?).

What concept of R is at work in this dichotomy?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Duncan,
 THanks for the reply.

I am looking at the technical point. The behavior you just described, as far as 
I know, is only for functions right? THre is no documentation ever, which says 
that the code looks for x in the search path. Could you please point me to some 
resources where I can find further information on lexical scoping for the code 
"typed" in the console (but not in a function)?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI


From: Duncan Murdoch 
Sent: Tuesday, April 4, 2023 7:48 PM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] on lexical scoping

On 04/04/2023 9:56 a.m., akshay kulkarni wrote:
> Dear Members,
>   I have the following code typed at the console 
> prompt:
>
> y   <-   x*10
>
> X has not been defined and the above code throws an object not found error. 
> That is, the global environment does not contain x. Why doesn't it look 
> further in the environment stack, like that of packages? There are thousands 
> of packages that contain the variable named  x. Of course, that happens if 
> the above code is in a function (or does it?).
>
> What concept of R is at work in this dichotomy?
>

First, some background:

Packages are associated with multiple environments.  There is the
internal one that the package sees, and the external one that contains
just the exports.

These are sometimes called the "package" environment and the "namespace"
environment, but I don't think those names are used consistently.
(There's another one containing the imports, but for these purposes,
it's indistinguishable from the internal one.)

When a package is loaded by loadNamespace("pkg"), nothing happens in the
global environment:  no new variables are visible.

When it is attached by library("pkg"), a lot more happens.  First, it is
loaded as above, then the search list is modified.  The global
environment is entry 1 in the search list; it stays there, but its
"parent" is set to a copy of the external environment from the new
package, and the parent of that environment is set to the previous
parent, the second entry in the search list.

Okay, so now you search for "x" in the global environment, and it's not
there.  It then goes to the other entries in the search list, which are
typically external environments from various packages.  None of those
packages export "x", so it is not found.

It doesn't matter if those packages use "x" without exporting it,
because R won't look at internal environments in this kind of search.

And it doesn't matter what happens in other packages that are not on the
search list (i.e. not "attached" because you never called library() or
require() on them), because they just aren't in the chain of
environments where R looks.

Duncan Murdoch

[[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] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Jeff,
  THanks a lot for the pithy reply...

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Jeff Newmiller 
Sent: Tuesday, April 4, 2023 7:43 PM
To: r-help@r-project.org ; akshay kulkarni 
; R help Mailing list 
Subject: Re: [R] on lexical scoping

Namespaces. Packages only export specific object names from their namespaces. 
But few instances of x would be found there.

Also, function argument lists are not added to the search path until the 
functions are running, and then the search path only goes through the 
environments in which the running functions were defined, not through the call 
stack.

Read Advanced R. [1]

[1] https://adv-r.hadley.nz/environments.html

On April 4, 2023 6:56:04 AM PDT, akshay kulkarni  wrote:
>Dear Members,
> I have the following code typed at the console 
> prompt:
>
>y   <-   x*10
>
>X has not been defined and the above code throws an object not found error. 
>That is, the global environment does not contain x. Why doesn't it look 
>further in the environment stack, like that of packages? There are thousands 
>of packages that contain the variable named  x. Of course, that happens if the 
>above code is in a function (or does it?).
>
>What concept of R is at work in this dichotomy?
>
>THanking you,
>Yours sincerely,
>AKSHAY M KULKARNI
>
>   [[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.

--
Sent from my phone. Please excuse my brevity.

[[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] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Duncan,
 THanks for the reply...!

So the takeaway is that define the symbol in the same environment before using 
it right!?

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Duncan Murdoch 
Sent: Tuesday, April 4, 2023 8:21 PM
To: akshay kulkarni ; Deepayan Sarkar 

Cc: R help Mailing list 
Subject: Re: [R] on lexical scoping

You can't change the basic way R searches, but you can ask for a
different kind of search.  For example, to see if "x" exists, you can use

  exists("x")

and it will do the default search, but

  exists("x", inherits = FALSE)

will only look in the current environment.  The get() function has a
similar argument which returns the value

Unfortunately these functions have overly complicated argument lists
because they are based on functions in S from 30-40 years ago, and it
had very different scoping rules.  My advice would be to ignore the
"where" and "frame" arguments, and always use "envir" if you want to say
where to look.

Duncan Murdoch

On 04/04/2023 10:28 a.m., akshay kulkarni wrote:
> Dear Deepayan,
>THanks for the pithy, pointed reply.
>
> But isn't it risky? Can I somehow get a warning when x is not defined in the 
> global environment but takes on a value from one of the loaded packages? any 
> packages for that?
>
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
> ________
> From: Deepayan Sarkar 
> Sent: Tuesday, April 4, 2023 7:51 PM
> To: akshay kulkarni 
> Cc: R help Mailing list 
> Subject: Re: [R] on lexical scoping
>
>
>
> On Tue, Apr 4, 2023 at 7:26 PM akshay kulkarni 
> mailto:akshay...@hotmail.com>> wrote:
> Dear Members,
>   I have the following code typed at the console 
> prompt:
>
> y   <-   x*10
>
> X has not been defined and the above code throws an object not found error. 
> That is, the global environment does not contain x.
>
> That is not the correct interpretation of the error. R will happily evaluate
>
> y   <-   pi*10
>
> even if the global environment does not contain pi. The "environments" where 
> R will look is given by
>
> search()
>
> If you manage to find a package that defines 'x' (and exports it), attaching 
> it will put the package on the search path, and then your call will indeed no 
> longer give an error.
>
> -Deepayan
>
> Why doesn't it look further in the environment stack, like that of packages? 
> There are thousands of packages that contain the variable named  x. Of 
> course, that happens if the above code is in a function (or does it?).
>
> What concept of R is at work in this dichotomy?
>
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
>
>  [[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.


[[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] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Duncan,
 THanks a lot..!!

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Duncan Murdoch 
Sent: Tuesday, April 4, 2023 8:49 PM
To: akshay kulkarni ; Deepayan Sarkar 

Cc: R help Mailing list 
Subject: Re: [R] on lexical scoping

No, there are lots of situations where that doesn't make sense.  You
don't want to have to define local copies of the functions from every
package you use, for example.

I think the takeaway is to learn how R scoping works, and keep things
simple.  That's one reason I tend to avoid "tidyverse" packages.  There
are a lot of really good ideas in those packages, but "tidy evaluation"
is far too complicated and hard to understand, and I think it confuses
people, so they don't understand the really very simple R scoping rules.

Duncan Murdoch

On 04/04/2023 10:59 a.m., akshay kulkarni wrote:
> Dear Duncan,
>   THanks for the reply...!
>
> So the takeaway is that define the symbol in the same environment before
> using it right!?
>
> Thanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
> 
> *From:* Duncan Murdoch 
> *Sent:* Tuesday, April 4, 2023 8:21 PM
> *To:* akshay kulkarni ; Deepayan Sarkar
> 
> *Cc:* R help Mailing list 
> *Subject:* Re: [R] on lexical scoping
> You can't change the basic way R searches, but you can ask for a
> different kind of search.  For example, to see if "x" exists, you can use
>
>exists("x")
>
> and it will do the default search, but
>
>exists("x", inherits = FALSE)
>
> will only look in the current environment.  The get() function has a
> similar argument which returns the value
>
> Unfortunately these functions have overly complicated argument lists
> because they are based on functions in S from 30-40 years ago, and it
> had very different scoping rules.  My advice would be to ignore the
> "where" and "frame" arguments, and always use "envir" if you want to say
> where to look.
>
> Duncan Murdoch
>
> On 04/04/2023 10:28 a.m., akshay kulkarni wrote:
>> Dear Deepayan,
>>THanks for the pithy, pointed reply.
>>
>> But isn't it risky? Can I somehow get a warning when x is not defined in the 
>> global environment but takes on a value from one of the loaded packages? any 
>> packages for that?
>>
>> THanking you,
>> Yours sincerely,
>> AKSHAY M KULKARNI
>> 
>> From: Deepayan Sarkar 
>> Sent: Tuesday, April 4, 2023 7:51 PM
>> To: akshay kulkarni 
>> Cc: R help Mailing list 
>> Subject: Re: [R] on lexical scoping
>>
>>
>>
>> On Tue, Apr 4, 2023 at 7:26 PM akshay kulkarni 
>> mailto:akshay...@hotmail.com>> wrote:
>> Dear Members,
>>   I have the following code typed at the console 
>> prompt:
>>
>> y   <-   x*10
>>
>> X has not been defined and the above code throws an object not found error. 
>> That is, the global environment does not contain x.
>>
>> That is not the correct interpretation of the error. R will happily evaluate
>>
>> y   <-   pi*10
>>
>> even if the global environment does not contain pi. The "environments" where 
>> R will look is given by
>>
>> search()
>>
>> If you manage to find a package that defines 'x' (and exports it), attaching 
>> it will put the package on the search path, and then your call will indeed 
>> no longer give an error.
>>
>> -Deepayan
>>
>> Why doesn't it look further in the environment stack, like that of packages? 
>> There are thousands of packages that contain the variable named  x. Of 
>> course, that happens if the above code is in a function (or does it?).
>>
>> What concept of R is at work in this dichotomy?
>>
>> THanking you,
>> Yours sincerely,
>> AKSHAY M KULKARNI
>>
>>  [[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
> <https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> <http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>[[alternative HTML version deleted]]
>>
>

Re: [R] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Deepayan,
  THanks for the pithy, pointed reply.

But isn't it risky? Can I somehow get a warning when x is not defined in the 
global environment but takes on a value from one of the loaded packages? any 
packages for that?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Deepayan Sarkar 
Sent: Tuesday, April 4, 2023 7:51 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] on lexical scoping



On Tue, Apr 4, 2023 at 7:26 PM akshay kulkarni 
mailto:akshay...@hotmail.com>> wrote:
Dear Members,
 I have the following code typed at the console 
prompt:

y   <-   x*10

X has not been defined and the above code throws an object not found error. 
That is, the global environment does not contain x.

That is not the correct interpretation of the error. R will happily evaluate

y   <-   pi*10

even if the global environment does not contain pi. The "environments" where R 
will look is given by

search()

If you manage to find a package that defines 'x' (and exports it), attaching it 
will put the package on the search path, and then your call will indeed no 
longer give an error.

-Deepayan

Why doesn't it look further in the environment stack, like that of packages? 
There are thousands of packages that contain the variable named  x. Of course, 
that happens if the above code is in a function (or does it?).

What concept of R is at work in this dichotomy?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Bert,
   THanks a lot. I will take a look at those...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Bert Gunter 
Sent: Tuesday, April 4, 2023 7:48 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] on lexical scoping

?search and ?environment

See also "The R Language Definition" manual for similar such questions.

-- Bert

On Tue, Apr 4, 2023 at 6:56 AM akshay kulkarni  wrote:
>
> Dear Members,
>  I have the following code typed at the console 
> prompt:
>
> y   <-   x*10
>
> X has not been defined and the above code throws an object not found error. 
> That is, the global environment does not contain x. Why doesn't it look 
> further in the environment stack, like that of packages? There are thousands 
> of packages that contain the variable named  x. Of course, that happens if 
> the above code is in a function (or does it?).
>
> What concept of R is at work in this dichotomy?
>
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
>
> [[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.


Re: [R] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Ducan,
Very informative! THanks a lot!

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Duncan Murdoch 
Sent: Tuesday, April 4, 2023 8:14 PM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] on lexical scoping

On 04/04/2023 10:35 a.m., akshay kulkarni wrote:
> Dear Duncan,
>   THanks for the reply.
>
> I am looking at the technical point. The behavior you just described, as
> far as I know, is only for functions right?

No, not at all.  Every function you write in R has an associated
environment (which you can find using environment(fn)).  That only
applies to searches taking place while evaluating the function.  The
starting point is a temporary environment to hold local variables,
called the "evaluation frame".  The parent of that environment is the
environment given by environment(fn).

When you type something at the top level, evaluation is done very
similarly, except that the starting point for the search is the global
environment.

THre is no documentation
> ever, which says that the code looks for x in the search path. Could you
> please point me to some resources where I can find further information
> on lexical scoping for the code "typed" in the console (but not in a
> function)?

See section 3.5.1 in the R Language Definition for a description of the
relation between the global environment and the search list.  See
section 2.1.10 in that manual for how R looks up variables.

Duncan Murdoch

>
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
>
> 
> *From:* Duncan Murdoch 
> *Sent:* Tuesday, April 4, 2023 7:48 PM
> *To:* akshay kulkarni ; R help Mailing list
> 
> *Subject:* Re: [R] on lexical scoping
> On 04/04/2023 9:56 a.m., akshay kulkarni wrote:
>> Dear Members,
>>   I have the following code typed at the console 
>> prompt:
>>
>> y   <-   x*10
>>
>> X has not been defined and the above code throws an object not found error. 
>> That is, the global environment does not contain x. Why doesn't it look 
>> further in the environment stack, like that of packages? There are thousands 
>> of packages that contain the variable  named  x. Of course, that happens if 
>> the above code is in a function
> (or does it?).
>>
>> What concept of R is at work in this dichotomy?
>>
>
> First, some background:
>
> Packages are associated with multiple environments.  There is the
> internal one that the package sees, and the external one that contains
> just the exports.
>
> These are sometimes called the "package" environment and the "namespace"
> environment, but I don't think those names are used consistently.
> (There's another one containing the imports, but for these purposes,
> it's indistinguishable from the internal one.)
>
> When a package is loaded by loadNamespace("pkg"), nothing happens in the
> global environment:  no new variables are visible.
>
> When it is attached by library("pkg"), a lot more happens.  First, it is
> loaded as above, then the search list is modified.  The global
> environment is entry 1 in the search list; it stays there, but its
> "parent" is set to a copy of the external environment from the new
> package, and the parent of that environment is set to the previous
> parent, the second entry in the search list.
>
> Okay, so now you search for "x" in the global environment, and it's not
> there.  It then goes to the other entries in the search list, which are
> typically external environments from various packages.  None of those
> packages export "x", so it is not found.
>
> It doesn't matter if those packages use "x" without exporting it,
> because R won't look at internal environments in this kind of search.
>
> And it doesn't matter what happens in other packages that are not on the
> search list (i.e. not "attached" because you never called library() or
> require() on them), because they just aren't in the chain of
> environments where R looks.
>
> Duncan Murdoch


[[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] aborting the execution of a script...

2023-04-12 Thread akshay kulkarni
Dear Duncan,
 What if I use source() with echo? I am using that in 
RStudio.

THanking you,
Yours sincerely
AKSHAY M KULKARNI

From: Duncan Murdoch 
Sent: Wednesday, April 12, 2023 5:35 PM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] aborting the execution of a script...

On 12/04/2023 7:03 a.m., akshay kulkarni wrote:
> Dear members,
>  I have a script which I source it interactively. 
> I have the following questions:
>
>
>1.  If there is an error in an expression, an error message is printed, 
> but the execution continues till the end of the script. I am sourcing with 
> echo. Is there any way to abort the execution when the first error occurs? 
> This happens with R CMD BATCH. If there is an error midway, an error message 
> is printed in the output file and the execution aborts. Is there a way to 
> mimic this with source()?
>2.  I am trying to abort the execution with ESC key, but again the same 
> thing happens: it aborts the current expression but continues on. How to 
> abort an R script with source()? I am using RStudio in windows.

I don't see this behaviour.  If I put this in a script:

  print(1)
  stop("here")
  print(2)

then execution stops at the "stop" line if I use source(), or R CMD
BATCH , or in RStudio, Run or Source gives the same behaviour.  I
think older versions of RStudio would have run all three lines using
Run, but all the other methods have stopped at the stop() line.

Duncan Murdoch




[[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] error in arfima...

2023-06-04 Thread akshay kulkarni
Dear Martin,
 REgrets to reply this late

I am staring at a conundrum never before encountered in my experience with R:

LYGH[[201]]
[1] 45.40  3.25  6.50  2.15
> arfima(LYGH[[201]])
 Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work = 
fdf$w) :
NA/NaN/Inf in foreign function call (arg 5)
> arfima(c(45.40,3.25,6.50,2.15))

Call:
  arfima(y = c(45.4, 3.25, 6.5, 2.15))

Coefficients:
   d
4.583013e-05
sigma[eps] = 18.01252
a list with components:
 [1] "log.likelihood"  "n"   "msg" "d"   
"ar"
 [6] "ma"  "covariance.dpq"  "fnormMin""sigma"   
"stderror.dpq"
[11] "correlation.dpq" "h"   "d.tol"   "M"   
"hessian.dpq"
[16] "length.w""residuals"   "fitted"  "call""x"
[21] "series"

Please note that the index of LYGH has changed from 202 to 201 due to some 
randomness in one of my function.

PLEASE HELP.

Output of dput LYGH[[201]]:

> dput(LYGH[[201]])
c(45.4, 3.25, 6.5, 2.149998)

output of session info()

sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 14393)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] parallel  stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] pbmcapply_1.5.1 imputeTS_3.3forecast_8.17.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7urca_1.3-3pillar_1.9.0  compiler_4.1.2
tseries_0.10-51
 [6] tools_4.1.2   xts_0.12.1nlme_3.1-153  lifecycle_1.0.3   
tibble_3.2.1
[11] gtable_0.3.3  lattice_0.20-45   pkgconfig_2.0.3   rlang_1.1.0   
cli_3.6.1
[16] rstudioapi_0.14   curl_4.3.2xml2_1.3.3dplyr_1.1.1   
generics_0.1.3
[21] vctrs_0.6.1   gridtext_0.1.5ggtext_0.1.2  lmtest_0.9-40 
grid_4.1.2
[26] nnet_7.3-16   tidyselect_1.2.0  glue_1.6.2R6_2.5.1  
fansi_1.0.4
[31] ggplot2_3.4.2 TTR_0.24.3magrittr_2.0.3scales_1.2.1  
quantmod_0.4.20
[36] timeDate_4021.106 colorspace_2.1-0  fracdiff_1.5-1quadprog_1.5-8
utf8_1.2.3
[41] stinepack_1.4 munsell_0.5.0 zoo_1.8-10


PLease Also note:

arfima(c(45.4, 3.25, 6.5, 2.149998))

Call:
  arfima(y = c(45.4, 3.25, 6.5, 2.149998))

Coefficients:
   d
4.583013e-05
sigma[eps] = 18.01252
a list with components:
 [1] "log.likelihood"  "n"   "msg" "d"   
"ar"
 [6] "ma"  "covariance.dpq"  "fnormMin""sigma"   
"stderror.dpq"
[11] "correlation.dpq" "h"   "d.tol"   "M"   
"hessian.dpq"
[16] "length.w""residuals"   "fitted"  "call""x"
[21] "series"


Many thanks in advance

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI



From: Martin Maechler 
Sent: Thursday, June 1, 2023 1:28 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] error in arfima...

>>>>> akshay kulkarni
>>>>> on Wed, 31 May 2023 20:55:33 + writes:

> dear members,

> I am using arfima() from forecast package to model a time
> series. The following is the code:

>> LYGH[[202]]
> [1] 45.40  3.25  6.50  2.15

>> arfima(LYGH[[202]])
> Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work 
= fdf$w) :
> NA/NaN/Inf in foreign function call (arg 5)

> I tried viewing .fdcov() with the following code:

> View(environment(fracdiff)$.fdcov)

> but I see no stop() with the above mentioned error message.

> Can you please help?

Well, as I am the maintainer of the *fracdiff* package,
I'm trying.  OTOH, as we will see below, you did not give us enough
information to really help you...

> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI

Your problem is not (yet) reproducible (*)
I've done the following in an "empty" (i.e. freshly started) R
session, R 4.3.0:

begin_R_transcript___save_as__arfima-ex.Rout__--
>
> lN <- loadedNamespaces()
> library(forecast)
Registered S3 method overwritten by 'quantmod':
  methodfrom
  as.z

Re: [R] error in arfima...

2023-06-05 Thread akshay kulkarni
Dear Martin,
 Sad that the bug is beyond your ken...

Fortunately, the error happens only rarely...The length of LYGH was 719 and 
there were only two such errors..I will just replace them with NA and make do.

By the by, what if I send LYGH as an attachment to your actual mail ( not the 
r-help mail)? Will it help? Can you then pinpoint the cause?

Or should I raise a bug report? If yes, how( I never raised one)?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Martin Maechler 
Sent: Monday, June 5, 2023 3:19 PM
To: akshay kulkarni 
Cc: Martin Maechler ; R help Mailing list 

Subject: Re: [R] error in arfima...


> Dear Martin,
>  REgrets to reply this late

> I am staring at a conundrum never before encountered in my experience with R:

> LYGH[[201]]
> [1] 45.40  3.25  6.50  2.15
> > arfima(LYGH[[201]])
>  Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work = 
> fdf$w) :
> NA/NaN/Inf in foreign function call (arg 5)
> > arfima(c(45.40,3.25,6.50,2.15))

> Call:
>   arfima(y = c(45.4, 3.25, 6.5, 2.15))

> Coefficients:
>d
> 4.583013e-05
> sigma[eps] = 18.01252
> a list with components:
>  [1] "log.likelihood"  "n"   "msg" "d"   
> "ar"
>  [6] "ma"  "covariance.dpq"  "fnormMin""sigma"   
> "stderror.dpq"
> [11] "correlation.dpq" "h"   "d.tol"   "M"   
> "hessian.dpq"
> [16] "length.w""residuals"   "fitted"  "call"
> "x"
> [21] "series"

> Please note that the index of LYGH has changed from 202 to 201 due to some 
> randomness in one of my function.

> PLEASE HELP.

> Output of dput LYGH[[201]]:

> > dput(LYGH[[201]])
> c(45.4, 3.25, 6.5, 2.149998)

> output of session info()

> sessionInfo()
> R version 4.1.2 (2021-11-01)
> Platform: x86_64-w64-mingw32/x64 (64-bit)


> Matrix products: default

> locale:
> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252

> attached base packages:
> [1] parallel  stats graphics  grDevices utils datasets  methods   base

> other attached packages:
> [1] pbmcapply_1.5.1 imputeTS_3.3forecast_8.17.0

> loaded via a namespace (and not attached):
>  [1] Rcpp_1.0.7urca_1.3-3pillar_1.9.0  compiler_4.1.2
> tseries_0.10-51
>  [6] tools_4.1.2   xts_0.12.1nlme_3.1-153  lifecycle_1.0.3   
> tibble_3.2.1
> [11] gtable_0.3.3  lattice_0.20-45   pkgconfig_2.0.3   rlang_1.1.0   
> cli_3.6.1
> [16] rstudioapi_0.14   curl_4.3.2xml2_1.3.3dplyr_1.1.1   
> generics_0.1.3
> [21] vctrs_0.6.1   gridtext_0.1.5ggtext_0.1.2  lmtest_0.9-40 
> grid_4.1.2
> [26] nnet_7.3-16   tidyselect_1.2.0  glue_1.6.2R6_2.5.1  
> fansi_1.0.4
> [31] ggplot2_3.4.2 TTR_0.24.3magrittr_2.0.3scales_1.2.1  
> quantmod_0.4.20
> [36] timeDate_4021.106 colorspace_2.1-0  fracdiff_1.5-1quadprog_1.5-8
> utf8_1.2.3
> [41] stinepack_1.4 munsell_0.5.0 zoo_1.8-10


> PLease Also note:

> arfima(c(45.4, 3.25, 6.5, 2.149998))

> Call:
>   arfima(y = c(45.4, 3.25, 6.5, 2.149998))

> Coefficients:
>d
> 4.583013e-05
> sigma[eps] = 18.01252
> a list with components:
>  [1] "log.likelihood"  "n"   "msg" "d"   
> "ar"
>  [6] "ma"  "covariance.dpq"  "fnormMin""sigma"   
> "stderror.dpq"
> [11] "correlation.dpq" "h"   "d.tol"   "M"   
> "hessian.dpq"
> [16] "length.w""residuals"   "fitted"  "call"
> "x"
> [21] "series"


> Many thanks in advance

> Thanking you,
> Yours sincerely,
> AKSHAY M KULKARNI

Hmm... indeed, "conundrum" may be a euphemism for the
situation. which clearly points to a bug *somewhere*.
As your dput() shows, the argument *is* a simple vector .. and
even if the default dput() may loose a few bits in
precison... you did show that with (possibly only almost)
identical argument, the error did not happen.

I really have no idea what's going on, 
Som

Re: [R] inconsistency in mclapply.....

2023-06-09 Thread akshay kulkarni
Dear Ivan,
  Thanks for the reply. I am pressurised by a fast approaching 
deadline and your reply calmed me...

Take a look at the following code:


debug at #26: LYG <- mclapply(LYGH, FUN = arfima, mc.cores = 2, 
mc.preschedule = FALSE)
Browse[2]> length(LYGH)
[1] 357
Browse[2]>
^C

Browse[2]> LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule = 
FALSE)
  | 
|   0%, 
ETA NA

I am debuuging a function FUN wherein the above expressions appear. The 
pbmclapply code works well if called inside FUN:
> FUN(arg)
Result..

But as you may note, it doesn't work while in debug mode

Also, if I replace pbmclapply by maclapply inside FUN, it hangs

You might be interested in this:

[ec2-user@ip-172-31-15-116 ~]$ exit
logout
There are stopped jobs.

THis occurs when I close R and try to exit the shell prompt( I am on an AWS EC2 
RHEL 8 Instance). Can this lead you somewhere? As of now I have quit R in my 
machine, so I can't get session info..but please let me know if you need it 
necessarily...

by the by, how do you run top when running R? I think at least in my machine, 
you have to quit R to get to the shell prompt...

I request you TO PLEASE reply to this mail as early as possible. I am facing an 
imminent deadline...please excuse my blatant violation of protocol, but 
deadlines are deadlines, right?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI



From: Ivan Krylov 
Sent: Saturday, June 10, 2023 1:43 AM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] inconsistency in mclapply.

On Fri, 9 Jun 2023 18:01:44 +0000
akshay kulkarni  wrote:

> > LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule =
> > FALSE)
>   |
>   
> |
>   0%, ETA NA^
>
> It just hangs.

My questions from the last time still stand:

0) What is your sessionInfo()? Maybe you're running a parallel BLAS
which doesn't always handle fork() or something. It may be worth
disabling BLAS-level parallelism as long as you're already trying to
use 100% of your processor by other means.

1) What does traceback() show after you interrupt pbmclapply? Most
likely, you would be interrupting selectChildren(), but if not, the
problem may lie in a very different place from what I'm expecting.

2) While pbmclapply is hung, without interrupting it, take a look at
the state of the system and the processes on it (are you still on RHEL?
use `top` or whatever task manager you're comfortable with).

 a) Is 100% of the CPU being used? 100% of one core? Is system mostly
 idle?

 b) Can you find the child processes launched by pbmclapply?

 c) Write down the PID of the child process and attach a debugger to
 it (If you're on RHEL, try following this guide:
 <https://beej.us/guide/bggdb/#attach>. If GDB asks you to install
 additional debug symbols by running debuginfo-install, follow its
 guidance and then restart GDB.) and obtain a backtrace. (In GDB, the
 command to obtain a backtrace is "backtrace".) Which function is the
 child process stuck in?

--
Best regards,
Ivan

[[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] inconsistency in mclapply.....

2023-06-09 Thread akshay kulkarni
Dear members,
  I am using pbmcapply to parellise my code. But the 
following code doesn't work:

> LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule = FALSE)
  | 
|   0%, 
ETA NA^

It just hangs.

But the following works:

>  LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2)
  
|==|
 100%, Elapsed 00:32
>  LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule = FALSE)
  
|==|
 100%, Elapsed 00:52

Any idea on why mc.preschedule = FALSE works after the one without it?

Many thanks ...

THanking you,

Yours sincerely,
AKSHAY M KULKARNI


[[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] inconsistency in mclapply.....

2023-06-09 Thread akshay kulkarni
Dear members,
 I think I have a hint:

The doc says:

mc.cleanup
 if set to TRUE then all children that have been forked by this 
function will be killed (by sending SIGTERM) before this function returns. 
Under normal circumstances mclapply waits for the children to deliver results, 
so this option usually has only effect when mclapply is interrupted. If set to 
FALSE then child processes are collected, but not forcefully terminated. As a 
special case this argument can be set to the number of the signal that should 
be used to kill the children instead of SIGTERM.
mc.allow.recursive

Unless true, calling mclapply in a child process will use the child and not 
fork again.

I think the child processes are not killed. I think I have to use one or both 
of the above arguments. Can you please shed some light on which one? ANd what 
goes on under the hood?
THanking you,Yours sincerely,AKSHAY M KULKARNI


From: R-help  on behalf of akshay kulkarni 

Sent: Friday, June 9, 2023 11:31 PM
To: R help Mailing list 
Subject: [R] inconsistency in mclapply.

Dear members,
  I am using pbmcapply to parellise my code. But the 
following code doesn't work:

> LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule = FALSE)
  | 
|   0%, 
ETA NA^

It just hangs.

But the following works:

>  LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2)
  
|==|
 100%, Elapsed 00:32
>  LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores = 2,mc.preschedule = FALSE)
  
|==|
 100%, Elapsed 00:52

Any idea on why mc.preschedule = FALSE works after the one without it?

Many thanks ...

THanking you,

Yours sincerely,
AKSHAY M KULKARNI


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


Re: [R] inconsistency in mclapply.....

2023-06-10 Thread akshay kulkarni
Dear Ivan,
   What if I switch to Ubuntu?
I had a similar ( but not exactly the same) problem way back in 2018 and 
switching to Ubuntu solved it.

Thanking you,
Yours sincerely,
Akshay M Kulkarni


From: Ivan Krylov 
Sent: Saturday, June 10, 2023 5:42 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] inconsistency in mclapply.

On Sat, 10 Jun 2023 11:49:10 +
akshay kulkarni  wrote:

> (gdb) backtrace
> #0  0x7f94b6454053 in gomp_team_barrier_wait_end () from 
> /lib64/libgomp.so.1
> #1  0x7f94b6452a7d in gomp_team_end () from /lib64/libgomp.so.1
> #2  0x7f94b3c280cf in exec_blas () from /lib64/libopenblaso.so.0
> #3  0x7f94b3c263e4 in gemm_thread_n () from /lib64/libopenblaso.so.0
> #4  0x7f94b3c39077 in dgetrs_N_parallel () from /lib64/libopenblaso.so.0
> #5  0x7f94b39f7f65 in dgesv_ () from /lib64/libopenblaso.so.0
> #6  0x7f948556aebe in La_solve () from /usr/lib64/R/modules//lapack.so
> #7  0x7f948556e555 in mod_do_lapack () from 
> /usr/lib64/R/modules//lapack.so
> #8  0x7f94b67a9c93 in bcEval () from /usr/lib64/R/lib/libR.so

I'm afraid this is exactly OpenBLAS trying to use OpenMP and failing
because it currently breaks in programs that fork().

Related links are <https://github.com/xianyi/OpenBLAS/issues/294> and
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60035>.

I was hoping that setting OPENBLAS_NUM_THREADS=1 would prevent OpenBLAS
from trying to use OpenMP, but that doesn't seem to work. If you
replace OPENBLAS_NUM_THREADS with OMP_NUM_THREADS (in order to limit
the number on OpenMP side), does it also not work?

How did you install OpenBLAS on this machine? If my environment
variable adjustments don't work, you'll need to either replace OpenBLAS
with a different build (for example, one that uses pthreads instead of
OpenMP, or a pure single-thread build, since you're already using
mclapply), or even remove OpenBLAS altogether and replace it with a
different BLAS that is fork()-safe.

--
Best regards,
Ivan

[[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] inconsistency in mclapply.....

2023-06-10 Thread akshay kulkarni
Dear Ivan,
 here is the comprehensive info you requested:

THis is the output of top when I run a function LOWn() with mclapply in it. It 
executes succesfully. (the number of cores in my machine is 2)

> LOWn(OHLCDataEP[[63]])

Tasks: 127 total,   3 running, 124 sleeping,   0 stopped,   0 zombie
%Cpu0  : 82.3 us, 16.7 sy,  0.0 ni,  0.0 id,  0.0 wa,  1.0 hi,  0.0 si,  0.0 st
%Cpu1  : 74.1 us, 24.9 sy,  0.0 ni,  0.0 id,  0.0 wa,  1.0 hi,  0.0 si,  0.0 st
MiB Mem :  15531.8 total,  11019.4 free,   3521.8 used,990.6 buff/cache
MiB Swap:  0.0 total,  0.0 free,  0.0 used.  11723.8 avail Mem






This is the output of top when I run function LOWp() with mclapply also in it. 
it hangs:


top - 07:48:08 up 54 min,  2 users,  load average: 0.02, 0.36, 0.34
Tasks: 127 total,   1 running, 126 sleeping,   0 stopped,   0 zombie
%Cpu0  :  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu1  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  15531.8 total,  10976.8 free,   3564.4 used,990.7 buff/cache
MiB Swap:  0.0 total,  0.0 free,  0.0 used.  11681.2 avail Mem

The mcalpply call only works the first time when I call it after starting an R 
session


TRaceback of after interrupting LOWp:


> LOWp(OHLCDataEP[[63]])
^C
There were 50 or more warnings (use warnings() to see the first 50)
> traceback()
3: selectChildren(jobs[!is.na(jobsp)], -1)
2: mclapply(LYGH, FUN = arfima, mc.cores = 2, mc.preschedule = FALSE) at 
#26
1: LOWp(OHLCDataEP[[63]])


I think child processes spawned by maclapply in FUN2 doesn't get killed...THis 
is from the top command AFTER interrupting FUN2 (sometimes there is only one R 
process)

 38615 ec2-user  20   0 1016432 400020  13392 S   0.0   2.5   0:02.05 R
38696 ec2-user  20   0 1016436 400416  13676 S   0.0   2.5   0:02.03 R

THis is the output when FUN2 is running:
 1526 ec2-user  20   0 1525784 651628  23040 S   0.0   4.1   0:11.90 R
 2616 ec2-user  20   0 1525784 634688   6092 S   0.0   4.0   0:00.03 R
   2617 ec2-user  20   0 1525784 634884   6288 S   0.0   4.0   0:00.02 R



THis is AFTER succesful completion of FUN1:
 38615 ec2-user  20   0 1016432 400020  13392 S   0.0   2.5   0:02.05 R
 38696 ec2-user  20   0 1016436 400416  13676 S   0.0   2.5   0:02.03 R

Please note that PIDs are same between FUN1 and FUN2, and also that when I am 
not parallelising there is only one R process:
1526 ec2-user  20   0 1227788 491248  21368 S   0.0   3.1   0:02.95 R



> sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux 8.6 (Ootpa)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblaso-r0.3.15.so

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] parallel  stats graphics  grDevices utils datasets  methods
[8] base

other attached packages:
[1] imputeTS_3.3pbmcapply_1.5.1 attempt_0.3.1   forecast_8.21

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10   urca_1.3-3pillar_1.9.0  compiler_4.2.1
 [5] tseries_0.10-54   xts_0.13.1lifecycle_1.0.3   tibble_3.2.1
 [9] gtable_0.3.3  nlme_3.1-157  lattice_0.20-45   pkgconfig_2.0.3
[13] rlang_1.1.1   cli_3.6.1 curl_5.0.0xml2_1.3.4
[17] generics_0.1.3vctrs_0.6.2   lmtest_0.9-40 grid_4.2.1
[21] nnet_7.3-17   ggtext_0.1.2  gridtext_0.1.5glue_1.6.2
[25] R6_2.5.1  fansi_1.0.4   ggplot2_3.4.2 TTR_0.24.3
[29] magrittr_2.0.3scales_1.2.1  quantmod_0.4.22   timeDate_4022.108
[33] colorspace_2.1-0  fracdiff_1.5-2quadprog_1.5-8utf8_1.2.3
[37] stinepack_1.4 munsell_0.5.0 zoo_1.8-12


THis is the output of jobs -l: (it doesn't do anything)

[ec2-user@ip-172-31-15-116 ~]$ jobs -l
[ec2-user@ip-172-31-15-116 ~]$

killall - SIGCONT  R has no effect


You had asked me to attach a debugger to the child processes. How do you get 
the child processes spawned by mclapply? For example, how do i identify, among 
the listed R processes above, the child processes?


Many thanks in advance

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI









From: Ivan Krylov 
Sent: Saturday, June 10, 2023 12:54 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] inconsistency in mclapply.

On Fri, 9 Jun 2023 21:19:11 +
akshay kulkarni  wrote:

> debug at #26: LYG <- mclapply(LYGH, FUN = arfima, mc.cores = 2,
> mc.preschedule = FALSE)
> Browse[2]> LYG <- pbmclapply(LYGH,FUN = arfima,mc.cores =
> 2,mc.preschedule = FALSE)
> |  | 0%, ETA NA

So if you interrupt the

Re: [R] inconsistency in mclapply.....

2023-06-10 Thread akshay kulkarni
/libR.so
#158 0x7f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so
#159 0x7f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so
#160 0x7f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so
#161 0x7f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so
#162 0x7f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so
#163 0x7f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so
#164 0x7f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so
#165 0x7f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so
#166 0x7f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so
#167 0x7f94b67c2255 in R_forceAndCall () from /usr/lib64/R/lib/libR.so
#168 0x7f94b66f429f in do_lapply () from /usr/lib64/R/lib/libR.so
#169 0x7f94b680232a in do_internal () from /usr/lib64/R/lib/libR.so
#170 0x7f94b67ad9b2 in bcEval () from /usr/lib64/R/lib/libR.so
#171 0x7f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so
#172 0x7f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so
#173 0x7f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so
#174 0x7f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so
#175 0x7f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so
#176 0x7f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so
#177 0x7f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so
#178 0x7f94b67b3834 in bcEval () from /usr/lib64/R/lib/libR.so
#179 0x7f94b67bca60 in Rf_eval () from /usr/lib64/R/lib/libR.so
#180 0x7f94b67be8af in R_execClosure () from /usr/lib64/R/lib/libR.so
#181 0x7f94b67bf837 in Rf_applyClosure () from /usr/lib64/R/lib/libR.so
#182 0x7f94b67bcc20 in Rf_eval () from /usr/lib64/R/lib/libR.so
#183 0x7f94b67f192a in Rf_ReplIteration () from /usr/lib64/R/lib/libR.so
#184 0x7f94b67f1c71 in R_ReplConsole () from /usr/lib64/R/lib/libR.so
#185 0x7f94b67f1d30 in run_Rmainloop () from /usr/lib64/R/lib/libR.so
#186 0x55f0700ed8ff in main ()


I hope this is enough for you to pinpoint the cause of the inconsistency..

WAITING EAGERLY FOR A POSITIVE REPLY

THanking you,
Yours sincerely,
AKSHAY M KULKARNI






From: Ivan Krylov 
Sent: Saturday, June 10, 2023 2:46 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] inconsistency in mclapply.

On Sat, 10 Jun 2023 08:42:37 +
akshay kulkarni  wrote:

> This is the output of top when I run function LOWp() with mclapply
> also in it. it hangs:

> %Cpu0  :  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0
> si,  0.0 st
> %Cpu1  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa, 0.0 hi,  0.0
> si,  0.0 st

I see. The system is idle.

> TRaceback of after interrupting LOWp:
>
>
> > LOWp(OHLCDataEP[[63]])
> ^C
> There were 50 or more warnings (use warnings() to see the first 50)

What are the warnings()?

> > traceback()
> 3: selectChildren(jobs[!is.na(jobsp)], -1)
> 2: mclapply(LYGH, FUN = arfima, mc.cores = 2, mc.preschedule = FALSE)
> at #26
> 1: LOWp(OHLCDataEP[[63]])

...and the parent is stuck waiting for at least some of the children.
The problem must be inside the child processes.

> BLAS/LAPACK: /usr/lib64/libopenblaso-r0.3.15.so

If you start R like this:

OPENBLAS_NUM_THREADS=1 R

...and confirm that Sys.getenv('OPENBLAS_NUM_THREADS') returns 1, then
try running your analysis, does it still get stuck?

There are reports complaining about OpenBLAS failing fork() tests when
built with OpenMP support, and this 'o' at the end of the shared
library name looks suspicious.

> You had asked me to attach a debugger to the child processes. How do
> you get the child processes spawned by mclapply? For example, how do
> i identify, among the listed R processes above, the child processes?

Make sure that there's only one R session running. Stray R processes
can be cleaned up by running killall R or rebooting the AWS virtual
machine.

Start R and run Sys.getpid(). This is the PID of the parent process.
Start your analysis and get it stuck. Do not interrupt the function,
let it keep waiting for the child process.

In a separate ssh connection or virtual terminal, run top. It should be
possible to type lowercase v to display a process tree, then navigate
it using arrow keys. Confirm that there is a parent R process with the
PID you saw above and a number of child processes branching from it with
different PIDs. If there's more than one child, try them both and see
if the results are different (hopefully not).

Run gdb and enter the following commands (substitute the value of the
PID for PID_OF_THE_CHILD_PROCESS):

attach PID_OF_THE_CHILD_PROCESS
thread apply all backtrace

If there's too much text and you can't copy it out of the terminal, use
the commands "set logging file gdb.log" and "set logging on", then get
the text output from

Re: [R] inconsistency in mclapply.....

2023-06-10 Thread akshay kulkarni
Dear Ivan,
  A million thanks for your precious time

Thanking you
Yours sincerely,
AkshayMKulkarni


From: Ivan Krylov 
Sent: Saturday, June 10, 2023 7:50 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] inconsistency in mclapply.

On Sat, 10 Jun 2023 13:46:12 +
akshay kulkarni  wrote:

>What if I switch to Ubuntu?
> I had a similar ( but not exactly the same) problem way back in 2018
> and switching to Ubuntu solved it.

You shouldn't have to switch distros for problems like this one.

What you need to switch is your OpenBLAS build: instead of using
OpenBLAS built with OpenMP support (which isn't even the default
when compiling OpenBLAS), use OpenBLAS built with pthreads support. It's
also likely, but not 100% guaranteed, that setting OMP_NUM_THREADS=1
will avoid the issue by never starting any additional threads for
OpenBLAS purposes. At least some documentation says that
OPENBLAS_NUM_THREADS is ignored on OpenMP builds of OpenBLAS, you
actually have to set OMP_NUM_THREADS=1 for it to take any effect.

I know very little about RHEL, but it seems that you already have a
pthreads build of OpenBLAS installed in
/usr/lib64/libopenblasp-r0.3.15.so; you just need to adjust the path to
the BLAS implementation used by R. If not, install the openblas-threads
package.

Can you use flexiblas
<https://cran.r-project.org/bin/linux/fedora/#blaslapack-switching> to
switch the BLAS implementation to OPENBLAS-THREADS? This should be
possible by using the flexiblas R package or by setting environment
variables
<https://github.com/mpimd-csc/flexiblas#selecting-the-backend-at-runtime>.

That said, I know for sure that on Debian and Ubuntu you get a choice
between libopenblas0-openmp / libopenblas0-pthread /
libopenblas0-serial, and installing any one of these packages except
libopenblas0-openmp should avoid the problem. (And the thread limit
should be set to 1 if you're running your tasks in parallel by other
means.)

--
Best regards,
Ivan

[[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] error in arfima...

2023-05-31 Thread akshay kulkarni
dear members,
I am using arfima() from forecast package to model 
a time series. The following is the code:

> LYGH[[202]]
[1] 45.40  3.25  6.50  2.15

> arfima(LYGH[[202]])
 Error in .fdcov(x, fdf$d, h, nar = nar, nma = nma, hess = hess, fdf.work = 
fdf$w) :
NA/NaN/Inf in foreign function call (arg 5)

I tried viewing .fdcov() with the following code:

View(environment(fracdiff)$.fdcov)

but I see no stop() with the above mentioned error message.

Can you please help?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] warnng to an error....

2023-06-17 Thread akshay kulkarni
Dear Duncan,
   THankls a lot...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Duncan Murdoch 
Sent: Saturday, June 17, 2023 11:36 PM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] warnng to an error

On 17/06/2023 1:16 p.m., akshay kulkarni wrote:
> Dear members,
>
>I have the following code:
>
>> FUN(OHLCDataEP[[63]])
> Error in (class(x) == "xts") || (class(x) == "zoo") :
>'length = 2' in coercion to 'logical(1)'
>> traceback()
> 2: ygix(x, "c") at #9
> 1: FUN(OHLCDataEP[[63]])
>> class(OHLCDataEP[[63]])
> [1] "xts" "zoo"
>
> The following is in ygix() :
>
> if((class(x) == "xts") || (class(x) == "zoo")
>
> I think this would have been a warning 
> (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1)
>  but I am on a ubuntu22.04 machine with R 4.3.0.
>
> What should I do? Change it to:
> if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}...

Changing it to `if (inherits(x, c("xts", "zoo")))` should do the same.
The vector of classes in the second argument is read as "any of these
classes".

Duncan Murdoch




[[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] inconsistency in mclapply.....

2023-06-17 Thread akshay kulkarni
Dear Ivan,
 I am reopening this thread because there are some new 
developments. I have switched to ubuntu and have used ropenblas() in ropenblas 
package to download the latest openblas (it is a version of skylake as you can 
see below in sessionInfo()). mclapply() is working fine now... My questions:


  1.  I was working on a two core machine just to test the code...tomorrow will 
be switching to a 48 core machine. Should I again download the latest openblas 
from ropenblas() or do you suggest testing the native openblas that is bundled 
in Ubuntu( it was a basic version of openblas..in my two core machine I tried 
the ropenblas() function without testing the native openblas...just for 
curiosity) ?
  2.  How do you pass the version of openblas to be installed with ropenblas()? 
The full file name? or just something like this:
libopenblas_skylakexp-r0.3.23.so  ?

> sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS/LAPACK: /opt/OpenBLAS/lib/libopenblas_skylakexp-r0.3.23.so;  LAPACK 
version 3.11.0

locale:
 [1] LC_CTYPE=C.UTF-8   LC_NUMERIC=C   LC_TIME=C.UTF-8
 [4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8LC_MESSAGES=C.UTF-8
 [7] LC_PAPER=C.UTF-8   LC_NAME=C  LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] parallel  stats graphics  grDevices utils datasets  methods
[8] base

other attached packages:
[1] pbmcapply_1.5.1 forecast_8.21   attempt_0.3.1   imputeTS_3.3

loaded via a namespace (and not attached):
 [1] gtable_0.3.3  compiler_4.3.0Rcpp_1.0.10   xml2_1.3.4
 [5] scales_1.2.1  lattice_0.20-45   ggplot2_3.4.2 R6_2.5.1
 [9] generics_0.1.3curl_5.0.1lmtest_0.9-40 ggtext_0.1.2
[13] tibble_3.2.1  munsell_0.5.0 nnet_7.3-17   timeDate_4022.108
[17] pillar_1.9.0  rlang_1.1.1   quantmod_0.4.22   utf8_1.2.3
[21] urca_1.3-3quadprog_1.5-8cli_3.6.1 magrittr_2.0.3
[25] xts_0.13.1grid_4.3.0gridtext_0.1.5lifecycle_1.0.3
[29] nlme_3.1-155  fracdiff_1.5-2vctrs_0.6.2   glue_1.6.2
[33] tseries_0.10-54   zoo_1.8-12fansi_1.0.4   colorspace_2.1-0
[37] TTR_0.24.3stinepack_1.4 pkgconfig_2.0.3



From: Ivan Krylov 
Sent: Saturday, June 10, 2023 7:50 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] inconsistency in mclapply.

On Sat, 10 Jun 2023 13:46:12 +0000
akshay kulkarni  wrote:

>What if I switch to Ubuntu?
> I had a similar ( but not exactly the same) problem way back in 2018
> and switching to Ubuntu solved it.

You shouldn't have to switch distros for problems like this one.

What you need to switch is your OpenBLAS build: instead of using
OpenBLAS built with OpenMP support (which isn't even the default
when compiling OpenBLAS), use OpenBLAS built with pthreads support. It's
also likely, but not 100% guaranteed, that setting OMP_NUM_THREADS=1
will avoid the issue by never starting any additional threads for
OpenBLAS purposes. At least some documentation says that
OPENBLAS_NUM_THREADS is ignored on OpenMP builds of OpenBLAS, you
actually have to set OMP_NUM_THREADS=1 for it to take any effect.

I know very little about RHEL, but it seems that you already have a
pthreads build of OpenBLAS installed in
/usr/lib64/libopenblasp-r0.3.15.so; you just need to adjust the path to
the BLAS implementation used by R. If not, install the openblas-threads
package.

Can you use flexiblas
<https://cran.r-project.org/bin/linux/fedora/#blaslapack-switching> to
switch the BLAS implementation to OPENBLAS-THREADS? This should be
possible by using the flexiblas R package or by setting environment
variables
<https://github.com/mpimd-csc/flexiblas#selecting-the-backend-at-runtime>.

That said, I know for sure that on Debian and Ubuntu you get a choice
between libopenblas0-openmp / libopenblas0-pthread /
libopenblas0-serial, and installing any one of these packages except
libopenblas0-openmp should avoid the problem. (And the thread limit
should be set to 1 if you're running your tasks in parallel by other
means.)

--
Best regards,
Ivan

[[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] warnng to an error....

2023-06-17 Thread akshay kulkarni
Dear Bert,
 Duncan's theory is workingprobably the same as yours...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Bert Gunter 
Sent: Saturday, June 17, 2023 11:28 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] warnng to an error

What is class(x) ??

I think you need to (re?) learn about S3 classes, which can in general be 
vectors. See ?class (the S3 portion) or any tutorial on S3 classes in R. I have 
no idea what you are trying to do, but I *suspect* it may be accomplished 
through S3 inheritance rather than changing the class vector. That is just a 
guess, however.

-- Bert

On Sat, Jun 17, 2023 at 10:27 AM akshay kulkarni 
mailto:akshay...@hotmail.com>> wrote:
Dear members,
  AN update:
I have changed the if clause to:

if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code}

but am bootless.

PLease help...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI


From: R-help 
mailto:r-help-boun...@r-project.org>> on behalf 
of akshay kulkarni mailto:akshay...@hotmail.com>>
Sent: Saturday, June 17, 2023 10:46 PM
To: R help Mailing list mailto:r-help@r-project.org>>
Subject: [R] warnng to an error

Dear members,

  I have the following code:

> FUN(OHLCDataEP[[63]])
Error in (class(x) == "xts") || (class(x) == "zoo") :
  'length = 2' in coercion to 'logical(1)'
> traceback()
2: ygix(x, "c") at #9
1: FUN(OHLCDataEP[[63]])
> class(OHLCDataEP[[63]])
[1] "xts" "zoo"

The following is in ygix() :

if((class(x) == "xts") || (class(x) == "zoo")

I think this would have been a warning 
(https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1)
 but I am on a ubuntu22.04 machine with R 4.3.0.

What should I do? Change it to:
if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}...

or is there any workaround?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI
[https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded]<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
R Warning 'length(x) = 2 > 1' in coercion to 
'logical(1)'<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
Using R 4.1.3 I observe: var - 0  if(is.data.frame(var) || 
is.vector(var)) var - as.matrix(var)  is.null(var) || (!is.matrix(var) 
 var == 0) || (dim(var)==c(1,1) 
stackoverflow.com<http://stackoverflow.com>




[[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<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] warnng to an error....

2023-06-17 Thread akshay kulkarni
Dear members,
  AN update:
I have changed the if clause to:

if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code}

but am bootless.

PLease help...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI


From: R-help  on behalf of akshay kulkarni 

Sent: Saturday, June 17, 2023 10:46 PM
To: R help Mailing list 
Subject: [R] warnng to an error

Dear members,

  I have the following code:

> FUN(OHLCDataEP[[63]])
Error in (class(x) == "xts") || (class(x) == "zoo") :
  'length = 2' in coercion to 'logical(1)'
> traceback()
2: ygix(x, "c") at #9
1: FUN(OHLCDataEP[[63]])
> class(OHLCDataEP[[63]])
[1] "xts" "zoo"

The following is in ygix() :

if((class(x) == "xts") || (class(x) == "zoo")

I think this would have been a warning 
(https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1)
 but I am on a ubuntu22.04 machine with R 4.3.0.

What should I do? Change it to:
if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}...

or is there any workaround?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI
[https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded]<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
R Warning 'length(x) = 2 > 1' in coercion to 
'logical(1)'<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
Using R 4.1.3 I observe: var - 0  if(is.data.frame(var) || 
is.vector(var)) var - as.matrix(var)  is.null(var) || (!is.matrix(var) 
 var == 0) || (dim(var)==c(1,1) 
stackoverflow.com




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


Re: [R] warnng to an error....

2023-06-19 Thread akshay kulkarni
Dear Martin,
 THanks  for your exhortation!

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Martin Maechler 
Sent: Monday, June 19, 2023 1:15 PM
To: akshay kulkarni 
Cc: Bert Gunter ; R help Mailing list 

Subject: Re: [R] warnng to an error

>>>>> akshay kulkarni
>>>>> on Sat, 17 Jun 2023 18:35:53 + writes:

> Dear Bert, Duncan's theory is workingprobably the same
> as yours...

"theory" .. well *truth*.



Note that I wrote a blog post I had hope would be read more
( --> and be cited more .. when helping peopling with such problems ;-))

Simple search ("google") for  "class think R blog"
or directly
  https://blog.r-project.org/2019/11/09/when-you-think-class.-think-again/

To say it again:   Using  something like

if(... class(x) == "" ..)

is almost always (*) bad code.
Everyone should learn about  inherits() and why sane R code
should use that instead.

---
*)  It may be ok, e.g., when `x` was very expliclitly
constructed in the same part of code a bit earlier

Martin


> THanking you, Yours sincerely, AKSHAY M KULKARNI
> ________ From: Bert Gunter
>  Sent: Saturday, June 17, 2023
> 11:28 PM To: akshay kulkarni  Cc: R
> help Mailing list  Subject: Re: [R]
> warnng to an error

> What is class(x) ??

> I think you need to (re?) learn about S3 classes, which
> can in general be vectors. See ?class (the S3 portion) or
> any tutorial on S3 classes in R. I have no idea what you
> are trying to do, but I *suspect* it may be accomplished
> through S3 inheritance rather than changing the class
> vector. That is just a guess, however.

> -- Bert

> On Sat, Jun 17, 2023 at 10:27 AM akshay kulkarni
> mailto:akshay...@hotmail.com>>
> wrote: Dear members, AN update: I have changed the if
> clause to:

> if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code}

> but am bootless.

> PLease help...

    > THanking you, Yours sincerely, AKSHAY M KULKARNI

>  From: R-help
> mailto:r-help-boun...@r-project.org>>
> on behalf of akshay kulkarni
> mailto:akshay...@hotmail.com>>
> Sent: Saturday, June 17, 2023 10:46 PM To: R help Mailing
> list mailto:r-help@r-project.org>>
> Subject: [R] warnng to an error

> Dear members,

>   I have the following code:

>> FUN(OHLCDataEP[[63]])
> Error in (class(x) == "xts") || (class(x) == "zoo") :
> 'length = 2' in coercion to 'logical(1)'
>> traceback()
> 2: ygix(x, "c") at #9 1: FUN(OHLCDataEP[[63]])
>> class(OHLCDataEP[[63]])
> [1] "xts" "zoo"

> The following is in ygix() :

> if((class(x) == "xts") || (class(x) == "zoo")

> I think this would have been a warning
> 
(https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1)
> but I am on a ubuntu22.04 machine with R 4.3.0.

> What should I do? Change it to: if((class(x)[1] == "xts")
> || (class(x)[2] == "zoo")) {code}...

> or is there any workaround?

> THanking you, Yours sincerely, AKSHAY M KULKARNI
> 
[https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded]<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
> R Warning 'length(x) = 2 > 1' in coercion to
> 
'logical(1)'<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
> Using R 4.1.3 I observe: var - 0 
> if(is.data.frame(var) || is.vector(var)) var -
> as.matrix(var)  is.null(var) || (!is.matrix(var)
>  var == 0) || (dim(var)==c(1,1) 
> stackoverflow.com<http://stackoverflow.com> 



> [[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<mailto:R-help@r-project.org> mailing
> list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
&

Re: [R] inconsistency in mclapply.....

2023-06-20 Thread akshay kulkarni
Dear Ivan,
 Yes, you were rightthe native BLAS version of my ubuntu 
system is:

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

Updating BLAS with ropenblas(), as you said,is superficial.

Will reverting back to you if stuck againwith mclapply..

A million thanks  again...

THanking you,
Yours sincerely,
AKSHAY M KULKKARNI

From: Ivan Krylov 
Sent: Sunday, June 18, 2023 12:42 AM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] inconsistency in mclapply.

� Sat, 17 Jun 2023 18:54:43 +
akshay kulkarni  �:

>   1.  I was working on a two core machine just to test the
> code...tomorrow will be switching to a 48 core machine. Should I
> again download the latest openblas from ropenblas() or do you suggest
> testing the native openblas that is bundled in Ubuntu

What's the version of OpenBLAS in the Ubuntu release you are running?
Unless you can see significant improvements regarding your CPU
architecture appearing since the version included in Ubuntu was
released, there's little reason to install a different version
manually. The whole point of a GNU/Linux distro is not having to
compile everything yourself. Ubuntu's build of OpenBLAS contains
multiple copies of the code targeted at different processors, including
yours.

> 2.  How do you pass the version of openblas to be installed with
> ropenblas()? The full file name? or just something like this:
> libopenblas_skylakexp-r0.3.23.so  ?

It looks like this function accepts the names of git tags in the
official OpenBLAS Git repository, but it's really the job of the
package maintainer to document important arguments like this one
properly. You can call bug.report(package = 'ropenblas') or write an
e-mail to maintainer('ropenblas') or locate the author's GitHub and ask
a question there.

--
Best regards,
Ivan

[[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] warnng to an error....

2023-06-17 Thread akshay kulkarni
Dear members,

  I have the following code:

> FUN(OHLCDataEP[[63]])
Error in (class(x) == "xts") || (class(x) == "zoo") :
  'length = 2' in coercion to 'logical(1)'
> traceback()
2: ygix(x, "c") at #9
1: FUN(OHLCDataEP[[63]])
> class(OHLCDataEP[[63]])
[1] "xts" "zoo"

The following is in ygix() :

if((class(x) == "xts") || (class(x) == "zoo")

I think this would have been a warning 
(https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1)
 but I am on a ubuntu22.04 machine with R 4.3.0.

What should I do? Change it to:
if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}...

or is there any workaround?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI
[https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded]
R Warning 'length(x) = 2 > 1' in coercion to 
'logical(1)'
Using R 4.1.3 I observe: var - 0  if(is.data.frame(var) || 
is.vector(var)) var - as.matrix(var)  is.null(var) || (!is.matrix(var) 
 var == 0) || (dim(var)==c(1,1) 
stackoverflow.com




[[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] mclapply enters into an infinite loop....

2023-05-16 Thread akshay kulkarni
Dear members,
 I am using arfima in an mclapply construction (from 
the parallel package):

Browse[2]> LYG <- mclapply(LYGH, FUN = arfima, mc.cores = detectCores())
^C
Browse[2]> LYG <- mclapply(LYGH[1:10], FUN = arfima, mc.cores = detectCores())
^C
Browse[2]> LYG <- mclapply(LYGH[1:2], FUN = arfima, mc.cores = detectCores())
^C

You can see that I am aborting the execution of mclapply. It doesn't finish 
even if I reduce the elements to be iterated over to 2. Why is it entering an 
infinite loop?

Please exhort me if this is to be posted in HPC list.

THanking you,
Yours sincerely,
ALSHAY M KULKARNI

[[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] mclapply enters into an infinite loop....

2023-05-20 Thread akshay kulkarni
Dear Ivan,
 I was on RHEL 8 with aws Ec2 z1d instance.

I infer by your words that this "bug" happens only sometimes..But I 
disagree...I run the same code multiple times within a span of 5 minutes, and 
the problem persistedAnyway I have removed the bug in the function and I 
hope that mclapply runs properly now( if it doesn't you are my only saviour!)

Many thanks for your geekish explanation.

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Ivan Krylov 
Sent: Saturday, May 20, 2023 6:00 PM
To: akshay kulkarni 
Cc: r-help@r-project.org 
Subject: Re: [R] mclapply enters into an infinite loop

� Sat, 20 May 2023 10:59:18 +0000
akshay kulkarni  �:

> By "holding a lock", you mean a bug in the process right

Well... one person's bug ("your threaded program breaks if I fork() the
process") is another person's documented behaviour ("of course it
does, it says 'please do not fork()' right in the manual"). Depending
on how you're running R (which operating system? are you using a
front-end? a multi-threaded BLAS?), this may be applicable, hence the
question about sessionInfo().

A GUI program may need multiple threads in order to stay responsive
(without looking hung and forgetting to repaint its window or
something) while doing something significant in the background. A
multi-threaded linear algebra library may create a thread per CPU core
in order to take your matrix products faster. Inside a process, some
resources have to be shared between the threads, like the bathroom in a
flat rented by multiple people together. "Holding a lock" is like
taking the key to the bathroom with the intent to occupy it for a
while: a completely normal action that prevents embarrassing accidents.

When you fork() a process, though, it ends up creating an exact copy of
the flat (process) just for you (the current thread), with none of the
flat-mates (other threads). If the bathroom was locked by someone else,
it stays locked, and there's no key anywhere.

There do exist mechanisms like pthread_atfork() that could be used to
prevent problems like this, but for that to work, *every* piece of code
that may be creating threads and taking locks inside your process
should be using them right. (The flat-mates need to know to give you
any keys they might be holding before the flat is fork()ed. It's enough
for one of them to forget one key to cause a problem.) The pragmatic
solution may be to avoid fork() and threads being used together.

--
Best regards,
Ivan

[[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] mclapply enters into an infinite loop....

2023-05-20 Thread akshay kulkarni
Dear Ivan,
 REgrets to reply this late...

By "holding a lock", you mean a bug in the process right (I am not a computer 
science guy, excuse my naivete)?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Ivan Krylov 
Sent: Thursday, May 18, 2023 1:08 PM
To: akshay kulkarni 
Cc: r-help@r-project.org 
Subject: Re: [R] mclapply enters into an infinite loop

On Wed, 17 May 2023 13:55:59 +0000
akshay kulkarni  wrote:

> So that means mclapply should run properly, i.e output a try class
> object and exit. But it didn't. Can you shed some light on why this
> happened?

What's your sessionInfo()? Are you using a GUI frontend?

mclapply() relies on the fork() system call, which is tricky to get
right in a process where other threads may exist at the same time: when
a process calls fork(), the child process ends up with the same
contents of virtual memory but no other threads at all. If a thread was
holding a lock when the process was forked, the lock will never be
released in the child process, leaving it stuck. Depending on how
you're running R, it may be threading issues or something else.

More information may be obtained by looking at traceback() after you
interrupt mclapply() (easy, but low information: did you interrupt
selectChildren() or some other function?) and attaching a C debugger to
the child process when you become sure it's stuck (hard, requires
additional preparation such as installing debugging symbols).

--
Best regards,
Ivan

[[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] mclapply enters into an infinite loop....

2023-05-17 Thread akshay kulkarni
Dear Jeff,
There was a problem in LYGH and lapply threw an error, but 
mclapply got stuck in an infinite loop. The doc for mclapply says that mclapply 
runs under try() with silent = TRUE. So that means mclapply should run 
properly, i.e output a try class object and exit. But it didn't. Can you shed 
some light on why this happened?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: R-help  on behalf of Jeff Newmiller 

Sent: Wednesday, May 17, 2023 5:24 AM
To: r-help@r-project.org 
Subject: Re: [R] mclapply enters into an infinite loop

It does not look to me like you are providing the necessary arguments to arfima.

Try making this work with lapply first... then try mclapply.

On May 16, 2023 3:10:45 PM PDT, akshay kulkarni  wrote:
>Dear members,
> I am using arfima in an mclapply construction (from 
> the parallel package):
>
>Browse[2]> LYG <- mclapply(LYGH, FUN = arfima, mc.cores = detectCores())
>^C
>Browse[2]> LYG <- mclapply(LYGH[1:10], FUN = arfima, mc.cores = detectCores())
>^C
>Browse[2]> LYG <- mclapply(LYGH[1:2], FUN = arfima, mc.cores = detectCores())
>^C
>
>You can see that I am aborting the execution of mclapply. It doesn't finish 
>even if I reduce the elements to be iterated over to 2. Why is it entering an 
>infinite loop?
>
>Please exhort me if this is to be posted in HPC list.
>
>THanking you,
>Yours sincerely,
>ALSHAY M KULKARNI
>
>   [[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.

--
Sent from my phone. Please excuse my brevity.

__
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] time series transformation....

2023-08-14 Thread akshay kulkarni
Dear Eric,
 THanks for the reply...will this also work with arfima() ? 
What if I want to fit a model like GARCH and friends?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Eric Berger 
Sent: Sunday, August 13, 2023 10:34 AM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] time series transformation

Hi Akshay,
The forecast package will do the BoxCox transform and automatically
backtransform the forecasts.
The package also handles xts objects.
For example, modifying the example from the help page of
forecast::forecast for Arima

> dt <- as.Date("2023-01-01") + 1:length(WWWusage)
> a <- xts(WWWusage, order.by=dt)
> fit1 <- Arima(a, c(3,1,0))
> fit2 <- Arima(a, lambda=0.5, c(3,1,0))  ## applies the Box-Cox transform with 
> lambda=0.5
> par(mfrow=c(1,2))
> plot(forecast(fit1))
> plot(forecast(fit2))

HTH,
Eric

p.s. RJH is the author/maintainer of the forecast package


On Sun, Aug 13, 2023 at 1:01 AM akshay kulkarni  wrote:
>
> dear members,
>  I have a heteroscedastic time series which I want to 
> transform to make it homoscedastic by a box cox transformation. I am using 
> Otexts by RJ hyndman and George Athanopolous as my textbook. They discuss 
> transformation and also say the fpp3 and the fable package automatically back 
> transforms the point forecast. they also discuss the process which I find to 
> be very cumbersome. Is there any R package which automatically back 
> transforms the point forecast when I use xts objects ( RJH and GA use tsibble 
> objects) with arfima/arima in the forecast package?
>
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
>
> [[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.


[R] time series transformation....

2023-08-12 Thread akshay kulkarni
dear members,
 I have a heteroscedastic time series which I want to 
transform to make it homoscedastic by a box cox transformation. I am using 
Otexts by RJ hyndman and George Athanopolous as my textbook. They discuss 
transformation and also say the fpp3 and the fable package automatically back 
transforms the point forecast. they also discuss the process which I find to be 
very cumbersome. Is there any R package which automatically back transforms the 
point forecast when I use xts objects ( RJH and GA use tsibble objects) with 
arfima/arima in the forecast package?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] time series transformation....

2023-08-14 Thread akshay kulkarni
Dear ERic,
 THanks a lot!

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Eric Berger 
Sent: Monday, August 14, 2023 11:04 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] time series transformation

Hi Akshay,
If you do
> help(package="forecast")

you will find that arfima is listed. Unfortunately, I don't see any
ARCH-type models there, but you should check out the help page
results.

Good luck,
Eric

On Mon, Aug 14, 2023 at 8:04 PM akshay kulkarni  wrote:
>
> Dear Eric,
>  THanks for the reply...will this also work with arfima() ? 
> What if I want to fit a model like GARCH and friends?
>
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
> 
> From: Eric Berger 
> Sent: Sunday, August 13, 2023 10:34 AM
> To: akshay kulkarni 
> Cc: R help Mailing list 
> Subject: Re: [R] time series transformation
>
> Hi Akshay,
> The forecast package will do the BoxCox transform and automatically
> backtransform the forecasts.
> The package also handles xts objects.
> For example, modifying the example from the help page of
> forecast::forecast for Arima
>
> > dt <- as.Date("2023-01-01") + 1:length(WWWusage)
> > a <- xts(WWWusage, order.by=dt)
> > fit1 <- Arima(a, c(3,1,0))
> > fit2 <- Arima(a, lambda=0.5, c(3,1,0))  ## applies the Box-Cox transform 
> > with lambda=0.5
> > par(mfrow=c(1,2))
> > plot(forecast(fit1))
> > plot(forecast(fit2))
>
> HTH,
> Eric
>
> p.s. RJH is the author/maintainer of the forecast package
>
>
> On Sun, Aug 13, 2023 at 1:01 AM akshay kulkarni  wrote:
> >
> > dear members,
> >  I have a heteroscedastic time series which I want 
> > to transform to make it homoscedastic by a box cox transformation. I am 
> > using Otexts by RJ hyndman and George Athanopolous as my textbook. They 
> > discuss transformation and also say the fpp3 and the fable package 
> > automatically back transforms the point forecast. they also discuss the 
> > process which I find to be very cumbersome. Is there any R package which 
> > automatically back transforms the point forecast when I use xts objects ( 
> > RJH and GA use tsibble objects) with arfima/arima in the forecast package?
> >
> > THanking you,
> > Yours sincerely,
> > AKSHAY M KULKARNI
> >
> > [[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.


[R] correction.....

2024-07-27 Thread akshay kulkarni
dear members,
  I want to mention that I am using the neural 
network model in caret. I forgot to mention it in the previous mail to you 
people

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] plotting nnet function....

2024-07-27 Thread akshay kulkarni
Dear members,
 I am using caret for modelling my data. It is a 
regression problem. My question is : how to plot the final model on the actual 
data points? The output of the model will be a nonlinear form of the activation 
function; I want to plot it on the data points. I have researched on web but to 
no effect. Like drawing a line on the original data points, for a linear model.

Thanking you,
Yours sincerely
AKSHAY M KULKARNI

[https://s-install.avcdn.net/ipm/preview/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]
  
Virus-free.www.avast.com

[[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] help on date objects...

2024-07-27 Thread akshay kulkarni
Dear members,
 WHy is the following code returning NA instead of 
the date?


> as.Date("2022-01-02", origin = "1900-01-01",  format = "%y%d%m")
[1] NA


Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] ts_regular....in tsbox

2024-07-27 Thread akshay kulkarni
dear members,
I have a data frame which contains, among others, a 
date object of monthly frequency which is not regular, i.e some months are 
omitted, and the main variable to be forecast, among others. Its name is 
vesselB.

I did the following code:

vesselBR <- ts_regular(vesselB)

but the missing months are not filled with NA. What should I do to insert NAs 
into the missing months? THe date column is of character class; should I make 
it Date class? Any other trick?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

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


<    1   2