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.


[R] data.table question

2023-08-30 Thread Naresh Gurbuxani


I want to apply interpolation functions from one data.table to each row
of another data.table.

interp.dt <- data.table(scen = rep(c("a", "b"), c(3, 3)), term = c(1,
20, 60, 1, 32, 72), shock = c(10, 20, 30, 9, 12, 32))

interp.fn <- function(df, x) with(df, approx(term, shock, xout = x)$y)

mydt <- data.table(name = c("xx", "yy", "zz"), term = c(22, 6, 18))

## Does not work
## scen.dt <- CJ(scen = c("a", "b"), mydt)

scen.dt <- lapply(c("a", "b"), function(scenario) {tempdt <- copy(mydt);
tempdt[, scen := scenario]})
scen.dt <- rbindlist(scen.dt)

## Works
interp.fn(interp.dt[scen == "a"], 22)

## Does not work
## scen.dt[, shock := interp.fn(interp.dt[scen == scen], term)]

## Works using data.frame apply
scen.dt[, "shock"] <- apply(scen.dt, 1, function(row) {
interp.fn(interp.dt[scen == row["scen"]], as.numeric(row["term"]))})

Is it possible to get both the above results using native data.table
methods?

Thanks,
Naresh

__
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] Problems with installing R packages from source and running C++ in R, even on fresh R installation

2023-08-30 Thread Jeff Newmiller
TL:DR there are at least three maybe four ways to address this depending on 
what you plan to do.

I usually adjust PATH to add Rtools using .Rprofile. But if you do that then if 
you want to use the command line to invoke R then you need to set the PATH 
separately when you start the shell. For this reason some people like to set it 
in the User Environment Variables control panel... but some Rtools programs 
conflict with some Cygwin tools so I don't like to set it globally that way 
since I use Cygwin a lot.

Finally, I _think_ RStudio will try to look up your Rtools and adjust settings 
automagically from within RStudio, but only if you have never previously 
configured it in your environment variables. But that is only inferred from 
reports I have read that imply they never manually set anything and it "just 
works"... I have always set it up manually. If this sounds attractive then you 
might try making sure Rtools is NOT in your PATH before RStudio starts up _and_ 
that it isn't configured in your .Rprofile file.

On August 30, 2023 12:10:28 PM PDT, Duncan Murdoch  
wrote:
>On 30/08/2023 2:59 p.m., Ivan Krylov wrote:
>> On Wed, 30 Aug 2023 16:31:20 +
>> Christophe Bousquet  wrote:
>> 
>>>   So, yes, it seems possible for R to localize paths related to
>>> Rtools... But then, I really do not get where things go wrong...
>> 
>> When installing packages containing code to compile, R eventually calls
>> R CMD SHLIB. Same thing happens with inline C++: it gets stored in a
>> temporary file, compiled into a *.dll using R CMD SHLIB and then loaded
>> using dyn.load().
>> 
>> Write the following into a file named hello.c:
>> 
>> #include 
>> #include 
>> SEXP hello(void) {
>>  SEXP ret = PROTECT(allocVector(STRSXP, 1));
>>  SET_STRING_ELT(ret, 0, mkChar("hello"));
>>  UNPROTECT(1);
>>  return ret;
>> }
>> 
>>  From within R, setwd() to the directory containing hello.c and run:
>> 
>> tools::Rcmd('SHLIB -n hello.c')
>> tools::Rcmd('SHLIB hello.c')
>> 
>> What do the commands print? Does the second command fail?
>> 
>> (Let's Cc: R-help@r-project.org in case people with more experience
>> debugging Windows problems have a better idea what's going on.)
>> 
>
>It sounds exactly as though Rtools files aren't on the path that's in effect 
>when R starts.  That's probably the one stored in the registry. In the old 
>days it was set in the System app in the Windows Control Panel under "Edit the 
>system environment variables".  I don't know if that's still true.
>
>Duncan Murdoch
>
>__
>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.


Re: [R] Book Recommendation

2023-08-30 Thread Greg Snow
Stephen,  I see lots of answers with packages and resources, but not
book recommendations.  I have used Introduction to Data Technologies
by Paul Murrell (https://www.stat.auckland.ac.nz/~paul/ItDT/) to teach
SQL and database design and would recommend looking at it as a
possibility.

On Mon, Aug 28, 2023 at 9:47 AM Stephen H. Dawson, DSL via R-help
 wrote:
>
> Good Morning,
>
>
> I am doing some research to develop a new course where I teach. I am
> looking for a book to use in the course content to teach accomplishing
> SQL in R.
>
> Does anyone know of a book on this topic to recommend for consideration?
>
>
> Thank You,
> --
> *Stephen Dawson, DSL*
> /Executive Strategy Consultant/
> Business & Technology
> +1 (865) 804-3454
> http://www.shdawson.com
>
> __
> 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.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

__
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] Problems with installing R packages from source and running C++ in R, even on fresh R installation

2023-08-30 Thread Duncan Murdoch

On 30/08/2023 2:59 p.m., Ivan Krylov wrote:

On Wed, 30 Aug 2023 16:31:20 +
Christophe Bousquet  wrote:


  So, yes, it seems possible for R to localize paths related to
Rtools... But then, I really do not get where things go wrong...


When installing packages containing code to compile, R eventually calls
R CMD SHLIB. Same thing happens with inline C++: it gets stored in a
temporary file, compiled into a *.dll using R CMD SHLIB and then loaded
using dyn.load().

Write the following into a file named hello.c:

#include 
#include 
SEXP hello(void) {
 SEXP ret = PROTECT(allocVector(STRSXP, 1));
 SET_STRING_ELT(ret, 0, mkChar("hello"));
 UNPROTECT(1);
 return ret;
}

 From within R, setwd() to the directory containing hello.c and run:

tools::Rcmd('SHLIB -n hello.c')
tools::Rcmd('SHLIB hello.c')

What do the commands print? Does the second command fail?

(Let's Cc: R-help@r-project.org in case people with more experience
debugging Windows problems have a better idea what's going on.)



It sounds exactly as though Rtools files aren't on the path that's in 
effect when R starts.  That's probably the one stored in the registry. 
In the old days it was set in the System app in the Windows Control 
Panel under "Edit the system environment variables".  I don't know if 
that's still true.


Duncan Murdoch

__
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] Problems with installing R packages from source and running C++ in R, even on fresh R installation

2023-08-30 Thread Ivan Krylov
On Wed, 30 Aug 2023 16:31:20 +
Christophe Bousquet  wrote:

>  So, yes, it seems possible for R to localize paths related to
> Rtools... But then, I really do not get where things go wrong...

When installing packages containing code to compile, R eventually calls
R CMD SHLIB. Same thing happens with inline C++: it gets stored in a
temporary file, compiled into a *.dll using R CMD SHLIB and then loaded
using dyn.load().

Write the following into a file named hello.c:

#include 
#include 
SEXP hello(void) {
SEXP ret = PROTECT(allocVector(STRSXP, 1));
SET_STRING_ELT(ret, 0, mkChar("hello"));
UNPROTECT(1);
return ret;
}

>From within R, setwd() to the directory containing hello.c and run:

tools::Rcmd('SHLIB -n hello.c')
tools::Rcmd('SHLIB hello.c')

What do the commands print? Does the second command fail?

(Let's Cc: R-help@r-project.org in case people with more experience
debugging Windows problems have a better idea what's going on.)

-- 
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] Problems with installing R packages from source and running C++ in R, even on fresh R installation

2023-08-30 Thread Ivan Krylov
В Wed, 30 Aug 2023 14:35:48 +
Christophe Bousquet  пишет:

> I followed your instructions and, yes, Rtools43 bash told me at the
> end "Hello world!".
> 
> Do you think this is a good sign? And do you have any idea how I
> could continue to solve the issue?

It is a good sign. Your Rtools43 installation is working, but R for
some reason doesn't know about it.

What is the value of Sys.getenv('PATH'), Sys.which('make'),
Sys.which('gcc') inside a running R session? Presumably, if PATH
starts with something like

C:/rtools43/x86_64-w64-mingw32.static.posix/bin;C:/rtools43/usr/bin;

...then both Make and the compiler should be available to R. If it
doesn't, it's worth trying to prepend it there.

-- 
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] Book Recommendation

2023-08-30 Thread Stephen H. Dawson, DSL via R-help

Thanks, Hadley. I appreciate your helpful assistance.


Kindest Regards,
*Stephen Dawson, DSL*
/Executive Strategy Consultant/
Business & Technology
+1 (865) 804-3454
http://www.shdawson.com


On 8/28/23 18:00, Hadley Wickham wrote:

These days I'd recommend duckdb
(https://cran.r-project.org/web/packages/duckdb/index.html) instead.
It's a similar design to RSQLite (i.e. you don't need a separate
server) but it's designed for the needs of data science.

Hadley

On Tue, Aug 29, 2023 at 9:22 AM Martin Møller Skarbiniks Pedersen
 wrote:

The SQLite is a good database to use.

https://cran.r-project.org/web/packages/RSQLite/vignettes/RSQLite.html

On Mon, Aug 28, 2023, 22:12 Stephen H. Dawson, DSL via R-help <
r-help@r-project.org> wrote:


This is an academic course. The effort now is to nail down the former. I
am pushing against a local db for the students. I prefer they focus on
the get-and-analyze efforts and not db administration efforts.



 [[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] Book Recommendation

2023-08-30 Thread Stephen H. Dawson, DSL via R-help

Thanks, Martin. I appreciate your helpful assistance.


Kindest Regards,
*Stephen Dawson, DSL*
/Executive Strategy Consultant/
Business & Technology
+1 (865) 804-3454
http://www.shdawson.com


On 8/28/23 17:14, Martin Møller Skarbiniks Pedersen wrote:

The SQLite is a good database to use.

https://cran.r-project.org/web/packages/RSQLite/vignettes/RSQLite.html

On Mon, Aug 28, 2023, 22:12 Stephen H. Dawson, DSL via R-help 
 wrote:



This is an academic course. The effort now is to nail down the
former. I
am pushing against a local db for the students. I prefer they
focus on
the get-and-analyze efforts and not db administration efforts.



__
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] Book Recommendation

2023-08-30 Thread Stephen H. Dawson, DSL via R-help

Thanks, Bill. I appreciate your helpful assistance.


Kindest Regards,
*Stephen Dawson, DSL*
/Executive Strategy Consultant/
Business & Technology
+1 (865) 804-3454
http://www.shdawson.com


On 8/29/23 00:07, William Michels wrote:

I'm a big fan of the sqldf package by Gabor Grothendieck:

"sqldf: Manipulate R Data Frames Using SQL"
https://CRAN.R-project.org/package=sqldf

The sqldf "README.html" converts to a 42 page PDF:
https://cran.r-project.org/web/packages/sqldf/readme/README.html

You can also find favorable blog posts for the sqldf package on the
web, notably a post (circa 2013) from Patrick Burns:
https://www.burns-stat.com/translating-r-sql-basics/

HTH,

Bill.

W. Michels, Ph.D.



On Mon, Aug 28, 2023 at 8:47 AM Stephen H. Dawson, DSL via R-help
 wrote:

Good Morning,


I am doing some research to develop a new course where I teach. I am
looking for a book to use in the course content to teach accomplishing
SQL in R.

Does anyone know of a book on this topic to recommend for consideration?


Thank You,
--
*Stephen Dawson, DSL*
/Executive Strategy Consultant/
Business & Technology
+1 (865) 804-3454
http://www.shdawson.com

__
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-es] Realizar anovas, por cada uno de los niveles de uno de los factores del ensayo

2023-08-30 Thread Juan Abasolo
Epa, tocayo!
No me queda claro cómo los estás haciendo, pero de una u otra manera, si
usás forcats::fct_infreq() , voy de memoria, se te van a ordenar según cuál
de los valores tengás más veces repetidos. Y si no es ese el que querés,
fijate dentro del paquete y vas a encontrar el que más te merezca.
fct_reorder()?

Suerte

Hau idatzi du Relloso Barrio, Juan Bautista (jbauti...@neiker.eus)
erabiltzaileak (2023 abu. 30(a), az. (11:50)):

> Buenos días.
>
> Una consulta. Alguiensabe como puedo conseguir que los gráficos Box plot
> salgan ordenador por los valores dela variable de mayo a menor o de menor a
> mayor?
>
> Muchas gracias.
>
> Un saludo.
>
> *Juan Bautista Relloso Barrio*
>
> Coordinador de Equipos e Infraestructuras | Técnico de Cultivos del
> Departamento de Producción Vegetal
>
> Talde eta Azpiegitura Koordinatzailea | Laborantza teknikaria Landare
> Ekoizpen Departamentua
>
> jbauti...@neiker.eus | M. 688 62 98 14
>
> *www.neiker.eus* 
> 
>  
> 
>
> *[image: ej_ekonomia_garapen_lateral] * [image:
> https://www.emakunde.euskadi.eus/contenidos/informacion/violencia_puntolila/eu_def/adjuntos/punto.lila.jpg]
>
>
>
> PRIBATUTASUN POLITIKA  | 
> POLÍTICA
> DE PRIVACIDAD  | LEGAL NOTICE
> 
>
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>


-- 
Juan Abasolo, PhD

Hizkuntzaren eta Literaturaren Didaktika Saila | EUDIA ikerketa taldea
Bilboko Hezkuntza Fakultatea
Euskal Herriko Unibertsitatea UPV/EHU

Sarriena auzoa z/g 48940 - Leioa (Bizkaia)

T   : (+34) 94 601 7567
Telegram: @JuanAbasolo
Skype   : abasolo72
Bloga   : juanabasolo.netlify.com
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] Realizar anovas, por cada uno de los niveles de uno de los factores del ensayo

2023-08-30 Thread Relloso Barrio, Juan Bautista
Buenos días.
Una consulta. Alguiensabe como puedo conseguir que los gráficos Box plot salgan 
ordenador por los valores dela variable de mayo a menor o de menor a mayor?
Muchas gracias.
Un saludo.
Juan Bautista Relloso Barrio
Coordinador de Equipos e Infraestructuras | Técnico de Cultivos del 
Departamento de Producción Vegetal
Talde eta Azpiegitura Koordinatzailea | Laborantza teknikaria Landare Ekoizpen 
Departamentua
jbauti...@neiker.eus  | M. 688 62 98 14
www.neiker.eus
[cid:image001.png@01D9DB38.08EC5DA0]  
 [cid:image002.png@01D9DB38.08EC5DA0]  
[cid:image003.png@01D9DB38.08EC5DA0]   
[cid:image004.png@01D9DB38.08EC5DA0] 
[cid:image005.png@01D9DB38.08EC5DA0][ej_ekonomia_garapen_lateral]   

[https://www.emakunde.euskadi.eus/contenidos/informacion/violencia_puntolila/eu_def/adjuntos/punto.lila.jpg]

PRIBATUTASUN POLITIKA | POLÍTICA 
DE PRIVACIDAD | LEGAL 
NOTICE

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Problems with installing R packages from source and running C++ in R, even on fresh R installation

2023-08-30 Thread Ivan Krylov
On Tue, 29 Aug 2023 14:41:40 +
Christophe Bousquet via R-help  wrote:

> (ii) the same issues keep coming back on my work laptop

It may be worth asking the IT department at work, just in case there is
a system to prevent unauthorised programs from running that interferes
with Rtools.

Are you comfortable using the command line? If you create a hello.c
file with the following contents:

#include 
int main(void) { printf("Hello world!\n"); }

...and then place it into %USERPROFILE% (C:/Users/Christophe Bousquet),
start "Rtools43 bash" from the Start menu and try the following command
line:

export PATH=/x86_64-w64-mingw32.static.posix/bin:$PATH
gcc -o hello.exe hello.c
./hello.exe

Does it say hello to you?

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