Re: [R] Reg: To change the x axis label in ts.plot function

2022-12-24 Thread Jim Lemon
Hi Upananda,
First, the date sequence you are using doesn't match the dates you
specify in your post. The code below may give you what you want:

# make up some prices
price<-c(seq(60,25,length.out=25),seq(25,70,length.out=54))+rnorm(79)
pricet <- ts(price, start = as.Date("2020-01-27"),end=as.Date("2021-07-26"),
frequency=1/7)
plot(pricet,xaxt="n")
axis_dates<-as.Date(c("2020-06-30","2021-01-01","2021-06-30"))
axis(1,at=axis_dates,labels=format(axis_dates,"%d/%m/%Y"))

Jim

On Sun, Dec 25, 2022 at 5:58 AM Upananda Pani  wrote:
>
>   Dear All,
>  I have the data set with daily dates (5-days trading in a week) and price
> data. I want to change the x axis labels to the plot. I am using ts.plot
> function to plot my data. My data spans from 2020-01-27 to 2021-07-30. I
> want to change it to D-M-Y first. Then I want to show all the dates with a
> one week gap in my x-axis label.
>
>  The following code I am using:
>  pricet <- ts(price, start = c(2020, 27), frequency = 260)
> plot.ts(pricet)
>
> Please advise me how to achieve the desired result. I have attached my data
> and the plot which I am currently getting with ts.plot.
>
> With sincere regards,
> Upananda Pani
> __
> 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@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] Reg: To change the x axis label in ts.plot function

2022-12-24 Thread CALUM POLWART
https://stackoverflow.com/questions/49679699/time-series-plot-change-x-axis-format-in-r

Is as good a solution as possible using ts I think.

On Sat, 24 Dec 2022, 18:58 Upananda Pani,  wrote:

>   Dear All,
>  I have the data set with daily dates (5-days trading in a week) and price
> data. I want to change the x axis labels to the plot. I am using ts.plot
> function to plot my data. My data spans from 2020-01-27 to 2021-07-30. I
> want to change it to D-M-Y first. Then I want to show all the dates with a
> one week gap in my x-axis label.
>
>  The following code I am using:
>  pricet <- ts(price, start = c(2020, 27), frequency = 260)
> plot.ts(pricet)
>
> Please advise me how to achieve the desired result. I have attached my data
> and the plot which I am currently getting with ts.plot.
>
> With sincere regards,
> Upananda Pani
> __
> 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] Reg: To change the x axis label in ts.plot function

2022-12-24 Thread Upananda Pani
  Dear All,
 I have the data set with daily dates (5-days trading in a week) and price
data. I want to change the x axis labels to the plot. I am using ts.plot
function to plot my data. My data spans from 2020-01-27 to 2021-07-30. I
want to change it to D-M-Y first. Then I want to show all the dates with a
one week gap in my x-axis label.

 The following code I am using:
 pricet <- ts(price, start = c(2020, 27), frequency = 260)
plot.ts(pricet)

Please advise me how to achieve the desired result. I have attached my data
and the plot which I am currently getting with ts.plot.

With sincere regards,
Upananda Pani
__
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] difference between script and a function....

2022-12-24 Thread akshay kulkarni
Dear Ivan,
   Thanks a lot.!

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Ivan Krylov 
Sent: Saturday, December 24, 2022 9:27 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] difference between script and a function

On Sat, 24 Dec 2022 15:47:14 +
akshay kulkarni  wrote:

> How do you debug if there is an error, particularly if I run the
> script from the BASH prompt?

Post-mortem debugging for non-interactive R scripts can be enabled by
setting options(error = quote(dump.frames("A_SUITABLE_FILE_NAME",
to.file = TRUE))) in your script. See ?dump.frames for more information.

When you're running command-line R interactively, the main tools at
your disposal are traceback() and browser() (see their respective help
pages). There are two main ways to use the browser: (1) by setting the
debugging flag on a function via debug(function) or debugonce(function)
-- you will land in the browser when the function is called -- and (2)
by setting options(error = recover), which will launch the browser at
the time of the crash, letting you walk the stack and inspect the
values of various variables.

For more information on pure-R debugging, see The R Inferno book:


--
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] difference between script and a function....

2022-12-24 Thread Ivan Krylov
On Sat, 24 Dec 2022 15:47:14 +
akshay kulkarni  wrote:

> How do you debug if there is an error, particularly if I run the
> script from the BASH prompt? 

Post-mortem debugging for non-interactive R scripts can be enabled by
setting options(error = quote(dump.frames("A_SUITABLE_FILE_NAME",
to.file = TRUE))) in your script. See ?dump.frames for more information.

When you're running command-line R interactively, the main tools at
your disposal are traceback() and browser() (see their respective help
pages). There are two main ways to use the browser: (1) by setting the
debugging flag on a function via debug(function) or debugonce(function)
-- you will land in the browser when the function is called -- and (2)
by setting options(error = recover), which will launch the browser at
the time of the crash, letting you walk the stack and inspect the
values of various variables.

For more information on pure-R debugging, see The R Inferno book:


-- 
Best regards,
Ivan

__
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] difference between script and a function....

2022-12-24 Thread akshay kulkarni
dear Ivan,
  Thanks for the reply. One last question:


  1.  How do you debug if there is an error, particularly if I run the script 
from the BASH prompt? The closest I have come to debugging a script is when I 
source the script in Rstudio. There everything is intiutive...but from the 
Linux prompt?

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Ivan Krylov 
Sent: Saturday, December 24, 2022 8:52 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] difference between script and a function

On Sat, 24 Dec 2022 14:54:52 +
akshay kulkarni  wrote:

> If there is  some error in the script, the error will be output to
> the stdout? Or to the file that it creates for saving the output of
> the script?

When using Rscript: to stderr, to be precise.

When using R CMD BATCH: to the Rout file.

> Will ALL the intermediate objects be stored ?

May I shamelessly plug my own package, depcache? Using its cache()
function, you can save intermediate objects into *.rds files in a
relatively transparent manner. By default, they are stored in a
subdirectory of the working directory. A downside is that I haven't
come up with a useful cache expiration strategy yet.

A more involved approach that will also let you access your
intermediates is provided by the "targets" package, not only on CRAN
but also peer-reviewed by rOpenSci.

--
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] difference between script and a function....

2022-12-24 Thread Ivan Krylov
On Sat, 24 Dec 2022 14:54:52 +
akshay kulkarni  wrote:

> If there is  some error in the script, the error will be output to
> the stdout? Or to the file that it creates for saving the output of
> the script?

When using Rscript: to stderr, to be precise.

When using R CMD BATCH: to the Rout file.

> Will ALL the intermediate objects be stored ?

May I shamelessly plug my own package, depcache? Using its cache()
function, you can save intermediate objects into *.rds files in a
relatively transparent manner. By default, they are stored in a
subdirectory of the working directory. A downside is that I haven't
come up with a useful cache expiration strategy yet.

A more involved approach that will also let you access your
intermediates is provided by the "targets" package, not only on CRAN
but also peer-reviewed by rOpenSci.

-- 
Best regards,
Ivan

__
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] difference between script and a function....

2022-12-24 Thread akshay kulkarni
Dear Simmons,
Thanks a lot. One more question:


  1.  If there is  some error in the script, the error will be output to the 
stdout? Or to the file that it creates for saving the output of the script?

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Andrew Simmons 
Sent: Saturday, December 24, 2022 8:18 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] difference between script and a function

1. The execution environment for a script is the global environment. Each R 
script run from a shell will be given its own global environment. Each R 
session has exactly one global environment, but you can have several active R 
sessions.

2. Using return in a script instead of a function will throw an error

Error: no function to return from, jumping to top level

3. You can use print(), cat(), and writeLines() to write to the output. It does 
not save your R objects before it exits the script. You could use save() or 
save.image() to save your objects, or possibly saveRDS() if you are only 
looking to save one object. You could also use source() if you just want the 
objects from another script.

4. Will you have shared access to the objects in another R session? No, objects 
are not shared, unless you've got something weird setup with external pointers. 
Each session has it owns global environment.

5. Any of the doc pages for the functions I listed above would help, you can 
also do

?utils::Rscript

[[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] difference between script and a function....

2022-12-24 Thread Andrew Simmons
1. The execution environment for a script is the global environment. Each R
script run from a shell will be given its own global environment. Each R
session has exactly one global environment, but you can have several active
R sessions.

2. Using return in a script instead of a function will throw an error

Error: no function to return from, jumping to top level

3. You can use print(), cat(), and writeLines() to write to the output. It
does not save your R objects before it exits the script. You could use
save() or save.image() to save your objects, or possibly saveRDS() if you
are only looking to save one object. You could also use source() if you
just want the objects from another script.

4. Will you have shared access to the objects in another R session? No,
objects are not shared, unless you've got something weird setup with
external pointers. Each session has it owns global environment.

5. Any of the doc pages for the functions I listed above would help, you
can also do

?utils::Rscript

[[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] difference between script and a function....

2022-12-24 Thread akshay kulkarni
Dear members,
I will be running scripts automatically in RHEL 
with crontab. I want to know the differences between running  a script and a 
function. in particular:


  1.  An execution environment will be created for the function. what about a 
script? Is the execution environment the global environment?
  2.  What happens if I use return() at the end of a script?
  3.  I came to know that when you use R CMD BATCH, a file will be created and 
the output will be saved to the file. How do I output what I want to output in 
a script? Should I use return()? Will ALL the intermediate objects be stored ?
  4.  When I run a script, it will have access to the objects in the global 
environment right? i.e I can use all the functions in the global environment, 
right?
  5.  Any links to resources for further information? How do i access the 
relevant documentation?

ANy help will be greatly appreciated...

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.