Re: [R] How to create an R input

2023-09-01 Thread Jeff Reichman
Jim

Yes that is helpful. Everything goes inside the function

Jeff

-Original Message-
From: Jim Lemon  
Sent: Wednesday, August 30, 2023 10:54 PM
To: Jeff Reichman 
Cc: r-help@r-project.org
Subject: Re: [R] How to create an R input

HI Jeff,
This might give you a start.

add_stuff<-function(x) {
 x<-xinc<-NA
 finished<-FALSE
 while(is.na(x))
  x<-as.numeric(readline("What number do you want to start? "))
 while(is.na(xinc) || !finished) {
  xinc<-as.numeric(readline("What number do you want to add? "))
  if(is.numeric(xinc)) x<-x+xinc
  answer<-unlist(strsplit(readline("Do you want to keep doing this?
(y/n) "),""))[1]
  finished<-toupper(answer)!="Y"
 }
 return(x)
}

Jim

On Thu, Aug 31, 2023 at 11:46 AM Jeff Reichman  wrote:
>
> R Help
>
>
>
> Trying to figure out how to create a simple program that will as the 
> user from a value input and simply add 5 units to that value then ask 
> the user for another value  and add 45 units to it  and on and on. 
> Then how does one exit the loop of program?
>
>
>
> # Create a function called `add_five`
>
> add_five <- function(x) {
>
>   # Add 5 to the input value
>
>   x + 5
>
> }
>
>
>
> readline(prompt = "Enter a number: ")
>
>
>
> Jeff
>
>
> [[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@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] How to create an R input

2023-08-31 Thread Ebert,Timothy Aaron
Add a break. Something like:
If (is.character(x)) break

If you have nested loops then a similar statement is needed for each level. 
"break" only exits the innermost loop.

Tim

-Original Message-
From: R-help  On Behalf Of Jeff Reichman
Sent: Wednesday, August 30, 2023 9:46 PM
To: r-help@r-project.org
Subject: [R] How to create an R input

[External Email]

R Help



Trying to figure out how to create a simple program that will as the user from 
a value input and simply add 5 units to that value then ask the user for 
another value  and add 45 units to it  and on and on. Then how does one exit 
the loop of program?



# Create a function called `add_five`

add_five <- function(x) {

  # Add 5 to the input value

  x + 5

}



readline(prompt = "Enter a number: ")



Jeff


[[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@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] How to create an R input

2023-08-30 Thread Jim Lemon
HI Jeff,
This might give you a start.

add_stuff<-function(x) {
 x<-xinc<-NA
 finished<-FALSE
 while(is.na(x))
  x<-as.numeric(readline("What number do you want to start? "))
 while(is.na(xinc) || !finished) {
  xinc<-as.numeric(readline("What number do you want to add? "))
  if(is.numeric(xinc)) x<-x+xinc
  answer<-unlist(strsplit(readline("Do you want to keep doing this?
(y/n) "),""))[1]
  finished<-toupper(answer)!="Y"
 }
 return(x)
}

Jim

On Thu, Aug 31, 2023 at 11:46 AM Jeff Reichman  wrote:
>
> R Help
>
>
>
> Trying to figure out how to create a simple program that will as the user
> from a value input and simply add 5 units to that value then ask the user
> for another value  and add 45 units to it  and on and on. Then how does one
> exit the loop of program?
>
>
>
> # Create a function called `add_five`
>
> add_five <- function(x) {
>
>   # Add 5 to the input value
>
>   x + 5
>
> }
>
>
>
> readline(prompt = "Enter a number: ")
>
>
>
> Jeff
>
>
> [[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@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] How to create an R input

2023-08-30 Thread Jeff Reichman
R Help

 

Trying to figure out how to create a simple program that will as the user
from a value input and simply add 5 units to that value then ask the user
for another value  and add 45 units to it  and on and on. Then how does one
exit the loop of program?

 

# Create a function called `add_five`

add_five <- function(x) {

  # Add 5 to the input value

  x + 5

}

 

readline(prompt = "Enter a number: ")

 

Jeff


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