Re: [R] function import file csv Openair

2024-04-30 Thread Avi Gross
Unless the functionality to read in a CSV file had special functionality,
it probably is simple enough to read it in using other available functions
like read.csv() or others available.

Many packages have functions they later remove as not really needed or if
others are available.


On Tue, Apr 30, 2024, 8:37 AM Ivan Krylov via R-help 
wrote:

> Dear Evelina Ballato,
>
> В Tue, 30 Apr 2024 10:36:32 +
> Evelina Ballato  пишет:
>
> > In the Openair package it is possible to restore the import csv file
> > function?
>
> This question is best addressed to the maintainer of the package (see
> the output of maintainer("openair")) if not to their GitHub issues at
> .
>
> Searching the manual of the 'openair' package for "CSV" gives a few
> results, so it might be possible that the functionality is still there,
> just under a different name. The manual also says that the package uses
> utils::read.csv to import the CSV files.
>
> Which particular functionality you are currently missing from the
> openair package?
>
> If all else fails, you can go to
> https://cran.r-project.org/src/contrib/Archive/openair/ and try to
> install an older version of the package (2.11?) from 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.
>

[[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 import file csv Openair

2024-04-30 Thread Ivan Krylov via R-help
Dear Evelina Ballato,

В Tue, 30 Apr 2024 10:36:32 +
Evelina Ballato  пишет:

> In the Openair package it is possible to restore the import csv file
> function?

This question is best addressed to the maintainer of the package (see
the output of maintainer("openair")) if not to their GitHub issues at
.

Searching the manual of the 'openair' package for "CSV" gives a few
results, so it might be possible that the functionality is still there,
just under a different name. The manual also says that the package uses
utils::read.csv to import the CSV files.

Which particular functionality you are currently missing from the
openair package?

If all else fails, you can go to
https://cran.r-project.org/src/contrib/Archive/openair/ and try to
install an older version of the package (2.11?) from 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.


[R] function import file csv Openair

2024-04-30 Thread Evelina Ballato
In the Openair package it is possible to restore the import csv file function? 
it has been removed in the latest versions.

Infinitely grateful

Evelina Ballato

Evelina Ballato
Arpa Piemonte
Dipartimento Territoriale
Piemonte Nord Est - sede di Omegna


Riservatezza/Confidentiality

Ai sensi del Regolamento UE 679/2016, del D. Legislativo n. 196/2003 nonch� del 
D. Legislativo n. 101/2018, le informazioni contenute in questo messaggio sono 
riservate e sono utilizzabili ad uso esclusivo del destinatario. Qualora il 
presente messaggio Le fosse pervenuto per errore, La preghiamo di eliminarlo, 
senza copiarlo e senza inoltrarlo a terzi e senza trattenerlo nei suoi archivi 
informatici o cartacei e di darne comunicazione all'indirizzo mail dal quale � 
pervenuto. Le ricordiamo che ogni violazione dei dati personali e punita dalla 
normativa sopra citata e, il contenuto del testo del presente messaggio, 
laddove utilizzato in violazione dei principi della riservatezza e segretezza 
della corrispondenza, � punito ai sensi delle leggi penali vigenti.

Pursuant to EU Regulation 679/2016, Legislative Decree no. 196/2003 and the 
Legislative Decree n. 101/2018, the information contained in this message is 
confidential and can be used for the exclusive use of the recipient. If this 
message was received by mistake, please delete it, without copying it and 
without forwarding it to third parties and without holding it in its computer 
or paper files and to notify the email address from which it was received. We 
remind you that any violation of personal data and punished by the 
aforementioned legislation and the content of the text of this message, when 
used in violation of the principles of confidentiality and secrecy of 
correspondence, is punished according to the current criminal laws.




[[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] Function environments serialize to a lot of data until they don't

2024-03-08 Thread Ivan Krylov via R-help
Hello R-help,

I've noticed that my 'parallel' jobs take too much memory to store and
transfer to the cluster workers. I've managed to trace it to the
following:

# `payload` is being written to the cluster worker.
# The function FUN had been created as a closure inside my package:
payload$data$args$FUN
# function (l, ...) 
# withCallingHandlers(fun(l$x, ...), error = .wraperr(l$name))
# 
# 

# The function seems to bring a lot of captured data with it.
e <- environment(payload$data$args$FUN)
length(serialize(e, NULL))
# [1] 738202878  
parent.env(e)
# 

# The parent environment has a name, so it all must be right here.
# What is it?

ls(e, all.names = TRUE)
# [1] "fun"
length(serialize(e$fun, NULL))
# [1] 317

# The only object in the environment is small!
# Where is the 700 megabytes of data?

length(serialize(e, NULL))
# [1] 536
length(serialize(payload$data$args$FUN, NULL))
# [1] 1722

And once I've observed `fun`, the environment becomes very small and
now can be serialized in a very compact manner.

I managed to work around it by forcing the promise and explicitly
putting `fun` in a small environment when constructing the closure:

.wrapfun <- function(fun) {
 e <- new.env(parent = loadNamespace('mypackage'))
 e$fun <- fun
 # NOTE: a naive return(function(...)) could serialize to 700
 # megabytes due to `fun` seemingly being a promise (?). Once the
 # promise is resolved, suddenly `fun` is much more compact.
 ret <- function(l, ...) withCallingHandlers(
  fun(l$x, ...),
  error = .wraperr(l$name)
 )
 environment(ret) <- e
 ret
}

Is this analysis correct? Could a simple f <- force(fun) have sufficed?
Where can I read more about this type of problems?

If this really is due to promises, what would be the downsides of
forcing them during serialization?

-- 
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] Function with large nested list

2023-12-18 Thread avi.e.gross
Emily,

I too copied/pasted your code in and it worked fine. I then asked for the
function definition and got it.

Did you put the entire text in? I mean nothing extra above or below except
maybe whitespace or comments?

What sometimes happens to make the code incomplete is to leave out a
matching parentheses of brace or bracket or sometimes quotes or using the
wrong kind of quote as in copying from a program like Microsoft Word.


-Original Message-
From: R-help  On Behalf Of Emily Bakker
Sent: Monday, December 18, 2023 4:56 AM
To: r-help@r-project.org
Subject: [R] Function with large nested list

Hello list,

I want to make a large rulebased algorithm, to provide decision support for
drug prescriptions. I have defined the algorithm in a function, with a for
loop and many if statements. The structure should be as follows:
1. Iterate over a list of drug names. For each drug:
2. Get some drug related data (external dataset). Row of a dataframe.
3.  Check if adaptions should be made to standard dosage and safety
information in case of contraindications. If patient has an indication,
update current dosage and safety information with the value from the
dataframe row. 
4. Save dosage and safety information in some lists and continue to the next
drug. 
5. When the iteration over all drugs is done, return the lists.

ISSUE:
So it is a very large function with many nested if statements. I have
checked the code structure multiple times, but i run into some issues. When
i try to run the function definiton, the command never "completes" in de
console. Instead of ">", the console shows "+". No errors are raised.

As I said, i have checked the structure multiple times, but cant find an
error. I have tried rebuilding it and testing each time i add a part. Each
part functions isolated, but not together in the same function. I can't find
any infinite loops either. 
I suspect the function may be too large, and i have to define functions for
each part separately. That isn't an issue necessarily, but i would still
like to know why my code won't run. And whether there are any downsides or
considerations for using many small functions.

Below is my code. I have left part of it out. There are six more parts like
the diabetes part that are similar.
I also use a lot of data/variabeles not included here, to try and keep
things compact. But I can provide additional information if helpful.
Thanks it advance for thinking along!!
Kind regards,
Emily

The code:

decision_algorithm <- function(AB_list, dataset_ab = data.frame(), diagnose
= 'cystitis', diabetes_status = "nee", katheter_status = "nee", 
   lang_QT_status = "nee", obesitas_status =
"nee", zwangerschap_status = "nee", 
   medicatie_actief =
data.frame(dict[["med_AB"]]), geslacht = "man", gfr=90){
  
  
  
  # vars
  list_AB_status <- setNames(as.list(rep("green", length(AB_list))),
names(AB_list)) #make a dict of all AB's and assign status green as deafault
for status
  list_AB_remarks <- setNames(as.list(rep("Geen opmerkingen",
length(AB_list))), names(AB_list)) #make a dict of all AB's and assign
"Geen" as default for remarks #Try empty list
  list_AB_dosering <- setNames(as.list(rep("Geen informatie",
length(AB_list))), names(AB_list)) # make named list of all AB's and assign
"Geen informatie", will be replaced with actual information in algorithm
  list_AB_duur <- setNames(as.list(rep("Geen informatie", length(AB_list))),
names(AB_list)) # make named list of all AB's and assign "Geen informatie",
will be replaced with actual information in algorithm
  
  # CULTURES #
  for (i in names(AB_list)) {

ab_data <- dataset_ab[dataset_ab$middel == i,] #get info for this AB
from dataset_ab

# Extract and split the diagnoses, dosering, and duur info for the
current antibiotic
ab_diagnoses <- str_split(ab_data$diagnoses, pattern = " \\| ")[[1]]
ab_diagnose_dosering <- str_split(ab_data$`diagnose dosering`, pattern =
" \\| ")[[1]]
ab_diagnose_duur <- str_split(ab_data$`diagnose duur`, pattern = " \\|
")[[1]]

# Find the index of the current diagnose in the ab_diagnoses list
diagnose_index <- match(diagnose, ab_diagnoses)

# Determine dosering and duur based on the diagnose_index
if (!is.na(diagnose_index)) {
  dosering <- ifelse(ab_diagnose_dosering[diagnose_index] ==
"standaard", ab_data$dosering, ab_diagnose_dosering[diagnose_index])
  duur <- ifelse(ab_diagnose_duur[diagnose_index] == "standaard",
ab_data$duur, ab_diagnose_duur[diagnose_index])
} else {
  # Use general dosering and duur as fallback if diagnose is not found
  doseri

Re: [R] Function with large nested list

2023-12-18 Thread Michael Dewey

Dear Emily

Comment in-line

On 18/12/2023 09:56, Emily Bakker wrote:

Hello list,

I want to make a large rulebased algorithm, to provide decision support for 
drug prescriptions. I have defined the algorithm in a function, with a for loop 
and many if statements. The structure should be as follows:
1. Iterate over a list of drug names. For each drug:
2. Get some drug related data (external dataset). Row of a dataframe.
3.  Check if adaptions should be made to standard dosage and safety information 
in case of contraindications. If patient has an indication, update current 
dosage and safety information with the value from the dataframe row.
4. Save dosage and safety information in some lists and continue to the next 
drug.
5. When the iteration over all drugs is done, return the lists.

ISSUE:
So it is a very large function with many nested if statements. I have checked the code structure multiple times, 
but i run into some issues. When i try to run the function definiton, the command never "completes" in 
de console. Instead of ">", the console shows "+". No errors are raised.


When my console returns a + is usually means I have left off the final 
parenthesis or given it an incomplete line.


Michael


As I said, i have checked the structure multiple times, but cant find an error. 
I have tried rebuilding it and testing each time i add a part. Each part 
functions isolated, but not together in the same function. I can't find any 
infinite loops either.
I suspect the function may be too large, and i have to define functions for 
each part separately. That isn't an issue necessarily, but i would still like 
to know why my code won't run. And whether there are any downsides or 
considerations for using many small functions.

Below is my code. I have left part of it out. There are six more parts like the 
diabetes part that are similar.
I also use a lot of data/variabeles not included here, to try and keep things 
compact. But I can provide additional information if helpful.
Thanks it advance for thinking along!!
Kind regards,
Emily

The code:

decision_algorithm <- function(AB_list, dataset_ab = data.frame(), diagnose = 'cystitis', 
diabetes_status = "nee", katheter_status = "nee",
lang_QT_status = "nee", obesitas_status = "nee", 
zwangerschap_status = "nee",
medicatie_actief = data.frame(dict[["med_AB"]]), geslacht 
= "man", gfr=90){
   
   
   
   # vars

   list_AB_status <- setNames(as.list(rep("green", length(AB_list))), 
names(AB_list)) #make a dict of all AB's and assign status green as deafault for status
   list_AB_remarks <- setNames(as.list(rep("Geen opmerkingen", length(AB_list))), 
names(AB_list)) #make a dict of all AB's and assign "Geen" as default for remarks #Try empty 
list
   list_AB_dosering <- setNames(as.list(rep("Geen informatie", length(AB_list))), 
names(AB_list)) # make named list of all AB's and assign "Geen informatie", will be replaced 
with actual information in algorithm
   list_AB_duur <- setNames(as.list(rep("Geen informatie", length(AB_list))), 
names(AB_list)) # make named list of all AB's and assign "Geen informatie", will be replaced 
with actual information in algorithm
   
   # CULTURES #

   for (i in names(AB_list)) {
 
 ab_data <- dataset_ab[dataset_ab$middel == i,] #get info for this AB from dataset_ab
 
 # Extract and split the diagnoses, dosering, and duur info for the current antibiotic

 ab_diagnoses <- str_split(ab_data$diagnoses, pattern = " \\| ")[[1]]
 ab_diagnose_dosering <- str_split(ab_data$`diagnose dosering`, pattern = " \\| 
")[[1]]
 ab_diagnose_duur <- str_split(ab_data$`diagnose duur`, pattern = " \\| 
")[[1]]
 
 # Find the index of the current diagnose in the ab_diagnoses list

 diagnose_index <- match(diagnose, ab_diagnoses)
 
 # Determine dosering and duur based on the diagnose_index

 if (!is.na(diagnose_index)) {
   dosering <- ifelse(ab_diagnose_dosering[diagnose_index] == "standaard", 
ab_data$dosering, ab_diagnose_dosering[diagnose_index])
   duur <- ifelse(ab_diagnose_duur[diagnose_index] == "standaard", 
ab_data$duur, ab_diagnose_duur[diagnose_index])
 } else {
   # Use general dosering and duur as fallback if diagnose is not found
   dosering <- ab_data$dosering
   duur <- ab_data$duur
 }
 
 list_AB_dosering[[i]] <- dosering

 list_AB_duur[[i]] <- duur
 
 if ((!is.null(AB_list[[i]]) && AB_list[[i]] == "I")) {

   list_AB_status[[i]] <- "yellow"
 list_AB_remarks[[i]] <- "Kweek verminderd gevoelig"
 } else if ((!is.null(AB_list[[i]]) && AB_list[[i]] == "R")) {
   list_AB_status[[i]] <- "red"
 list_AB_remarks[[i]] <- "Kweek resistent"
 }else if ((!is.null(AB_list[[i]]) && AB_list[[i]] == "S")) {
   next
 } else {
   list_AB_status[[i]] <- "yellow"
 list_AB_remarks[[i]] <- "Geen kweekgegevens"
 }
   
 
 # 

Re: [R] Function with large nested list

2023-12-18 Thread Ivan Krylov
В Mon, 18 Dec 2023 09:56:16 +
Emily Bakker  пишет:

> When i try to run the function definiton, the command never
> "completes" in de console.

How do you run the function definition? I copied and pasted your
example into a character variable and gave it to parse(text = ...). It
parsed successfully.

Splitting the function into multiple smaller functions is the usual
advice. It should help here too. When you decompose a large function
into a set of smaller functions, it becomes easier to reason about them
and test them individually. (It is also possible to have too many small
functions; it is important to find a balanced solution.)

If you find yourself making a decision based on a fixed set of strings,
consider switch() and match.arg(). If a set of possible values for a
factor is limited to true / false / don't know, it may help to switch
to R's native TRUE / FALSE / NA_logical_ values instead of strings
(which may contain typos).

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


[R] Function with large nested list

2023-12-18 Thread Emily Bakker
Hello list,

I want to make a large rulebased algorithm, to provide decision support for 
drug prescriptions. I have defined the algorithm in a function, with a for loop 
and many if statements. The structure should be as follows:
1. Iterate over a list of drug names. For each drug:
2. Get some drug related data (external dataset). Row of a dataframe.
3.  Check if adaptions should be made to standard dosage and safety information 
in case of contraindications. If patient has an indication, update current 
dosage and safety information with the value from the dataframe row. 
4. Save dosage and safety information in some lists and continue to the next 
drug. 
5. When the iteration over all drugs is done, return the lists.

ISSUE:
So it is a very large function with many nested if statements. I have checked 
the code structure multiple times, but i run into some issues. When i try to 
run the function definiton, the command never "completes" in de console. 
Instead of ">", the console shows "+". No errors are raised.

As I said, i have checked the structure multiple times, but cant find an error. 
I have tried rebuilding it and testing each time i add a part. Each part 
functions isolated, but not together in the same function. I can't find any 
infinite loops either. 
I suspect the function may be too large, and i have to define functions for 
each part separately. That isn't an issue necessarily, but i would still like 
to know why my code won't run. And whether there are any downsides or 
considerations for using many small functions.

Below is my code. I have left part of it out. There are six more parts like the 
diabetes part that are similar.
I also use a lot of data/variabeles not included here, to try and keep things 
compact. But I can provide additional information if helpful.
Thanks it advance for thinking along!!
Kind regards,
Emily

The code:

decision_algorithm <- function(AB_list, dataset_ab = data.frame(), diagnose = 
'cystitis', diabetes_status = "nee", katheter_status = "nee", 
   lang_QT_status = "nee", obesitas_status = "nee", 
zwangerschap_status = "nee", 
   medicatie_actief = data.frame(dict[["med_AB"]]), 
geslacht = "man", gfr=90){
  
  
  
  # vars
  list_AB_status <- setNames(as.list(rep("green", length(AB_list))), 
names(AB_list)) #make a dict of all AB's and assign status green as deafault 
for status
  list_AB_remarks <- setNames(as.list(rep("Geen opmerkingen", 
length(AB_list))), names(AB_list)) #make a dict of all AB's and assign "Geen" 
as default for remarks #Try empty list
  list_AB_dosering <- setNames(as.list(rep("Geen informatie", 
length(AB_list))), names(AB_list)) # make named list of all AB's and assign 
"Geen informatie", will be replaced with actual information in algorithm
  list_AB_duur <- setNames(as.list(rep("Geen informatie", length(AB_list))), 
names(AB_list)) # make named list of all AB's and assign "Geen informatie", 
will be replaced with actual information in algorithm
  
  # CULTURES #
  for (i in names(AB_list)) {

ab_data <- dataset_ab[dataset_ab$middel == i,] #get info for this AB from 
dataset_ab

# Extract and split the diagnoses, dosering, and duur info for the current 
antibiotic
ab_diagnoses <- str_split(ab_data$diagnoses, pattern = " \\| ")[[1]]
ab_diagnose_dosering <- str_split(ab_data$`diagnose dosering`, pattern = " 
\\| ")[[1]]
ab_diagnose_duur <- str_split(ab_data$`diagnose duur`, pattern = " \\| 
")[[1]]

# Find the index of the current diagnose in the ab_diagnoses list
diagnose_index <- match(diagnose, ab_diagnoses)

# Determine dosering and duur based on the diagnose_index
if (!is.na(diagnose_index)) {
  dosering <- ifelse(ab_diagnose_dosering[diagnose_index] == "standaard", 
ab_data$dosering, ab_diagnose_dosering[diagnose_index])
  duur <- ifelse(ab_diagnose_duur[diagnose_index] == "standaard", 
ab_data$duur, ab_diagnose_duur[diagnose_index])
} else {
  # Use general dosering and duur as fallback if diagnose is not found
  dosering <- ab_data$dosering
  duur <- ab_data$duur
}

list_AB_dosering[[i]] <- dosering
list_AB_duur[[i]] <- duur

if ((!is.null(AB_list[[i]]) && AB_list[[i]] == "I")) {
  list_AB_status[[i]] <- "yellow"
list_AB_remarks[[i]] <- "Kweek verminderd gevoelig"
} else if ((!is.null(AB_list[[i]]) && AB_list[[i]] == "R")) {
  list_AB_status[[i]] <- "red"
list_AB_remarks[[i]] <- "Kweek resistent"
}else if ((!is.null(AB_list[[i]]) && AB_list[[i]] == "S")) {
  next
} else {
  list_AB_status[[i]] <- "yellow"
list_AB_remarks[[i]] <- "Geen kweekgegevens"
}
  

# counters, for check if dosering / duur are updated more than once
dosering_update_count <- 0
duur_update_count <- 0

# DIABETES #
if (diabetes_status == "ja") {
  if (ab_data$'diabetes veiligheid' == "ja") {
lis

Re: [R] Could you manually replicate execution of a R function

2023-09-22 Thread Brian Smith
Hi Ivan,

Thanks for pointing this out. It now matches.

Thanks and regards,

On Thu, 21 Sept 2023 at 13:04, Ivan Krylov  wrote:
>
> On Tue, 19 Sep 2023 23:09:18 +0530
> Brian Smith  wrote:
>
> > C = rep(0, length(D))
> > N = length(D)
>
> In the VaRDurTest function, there's additional code between these two
> expressions that deals with censoring if head(VaR.ind, 1) == 0 or
> tail(VaR.ind, 1) == 0. Both of these are true for your input data.
>
> --
> 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] Could you manually replicate execution of a R function

2023-09-21 Thread Ivan Krylov
On Tue, 19 Sep 2023 23:09:18 +0530
Brian Smith  wrote:

> C = rep(0, length(D))
> N = length(D)

In the VaRDurTest function, there's additional code between these two
expressions that deals with censoring if head(VaR.ind, 1) == 0 or
tail(VaR.ind, 1) == 0. Both of these are true for your input data.

-- 
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] Could you manually replicate execution of a R function

2023-09-20 Thread Jorgen Harmse via R-help
There may be collisions between variables in .GlobalEnv and variables in the 
function-call environment, and the parent of the function-call environment 
probably includes functions & other variables not available in .GlobalEnv. (If 
the function calls substitute or anything like that then the problem becomes 
even harder.) I would probably use the debugger to step into the function. If 
you want more control then create an environment that resembles what would be 
created in a function call:

env.func <- new.env(parent=environment(f))
delayedAssign(assign.env=env.func, �.) for everything you pass in
delayedAssign(assign.env=env.func, eval.env=env.func, �.) for anything that 
will take a default value
eval(envir=env.func, �.) or evalq(envir=env.func, �.) to execute parts of the 
function body or anything else

You can even coerce body(f) to a character, strip the leading �{�, and 
parse(text=�.) to break the function into expressions. That might be easier 
than copy-pasting function code.

Regards,
Jorgen Harmse.


Message: 1
Date: Tue, 19 Sep 2023 23:09:18 +0530
From: Brian Smith 
To: r-help@r-project.org
Subject: [R] Could you manually replicate execution of a R function
Message-ID:

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

Hi,

I have trying to replicate a function from rugarch package manually.
Below is the calculation based on the function,

�

[[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] Unable to manually replicate execution of a R function

2023-09-20 Thread Brian Smith
Hi,

** In may earlier post there were some typo, so reposting the same
after correction**

I am trying to replicate a function from rugarch package manually.
Below is the calculation based on the function,

library(rugarch)
data(dji30ret)
spec = ugarchspec(mean.model = list(armaOrder = c(1,1), include.mean = TRUE),
variance.model = list(model = "gjrGARCH"), distribution.model = "sstd")
fit = ugarchfit(spec, data = dji30ret[1:1000, 1, drop = FALSE])
spec2 = spec
setfixed(spec2)<-as.list(coef(fit))
filt = ugarchfilter(spec2, dji30ret[1001:2500, 1, drop = FALSE], n.old = 1000)
actual = dji30ret[1001:2500,1]
# location+scale invariance allows to use [mu + sigma*q(p,0,1,skew,shape)]
VaR = fitted(filt) + sigma(filt)*qdist("sstd", p=0.05, mu = 0, sigma = 1,
skew = coef(fit)["skew"], shape=coef(fit)["shape"])
alpha = 0.05
conf.level = 0.95

VaRDurTest(0.05, actual, VaR)$b ## 1.019356


Now I want to replicate the calculation manually as below,


VaR.ind = ifelse(actual < VaR, 1, 0)
N = sum(VaR.ind)
TN = length(VaR.ind)
D = diff(which(VaR.ind == 1))
C = rep(0, length(D))
N = length(D)

pweibull = function (D, a, b, survival = FALSE)
{
cdf = 1 - exp(-(a * D)^b)
if (survival)
cdf = 1 - cdf
return(cdf)
}
dweibull = function (D, a, b, log = FALSE)
{
pdf = (b * log(a) + log(b) + (b - 1) * log(D) - (a * D)^b)
if (!log)
pdf = exp(pdf)
return(pdf)
}
likDurationW = function (pars, D, C, N)
{
b = pars[1]
a = ((N - C[1] - C[N])/(sum(D^b)))^(1/b)
lik = C[1] * log(pweibull(D[1], a, b, survival = TRUE)) +
(1 - C[1]) * dweibull(D[1], a, b, log = TRUE) + sum(dweibull(D[2:(N -
1)], a, b, log = TRUE)) + C[N] * log(pweibull(D[N],
a, b, survival = TRUE)) + (1 - C[N]) * dweibull(D[N],
a, b, log = TRUE)
if (!is.finite(lik) || is.nan(lik))
lik = 100
else lik = -lik
return(lik)
}
optim(par = 2, fn = likDurationW, gr = NULL, D = D, C = C, N = N,
method = "L-BFGS-B", lower = 0.001, upper = 10, control = list(trace =
0))$par  ## 1.029628

I fail to understand why there has to be a difference. Could you
please help to find the reason?

> sessionInfo()

R version 4.2.2 (2022-10-31)

Platform: x86_64-apple-darwin17.0 (64-bit)

Running under: macOS Big Sur ... 10.16


Matrix products: default

BLAS:   
/Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib

LAPACK: 
/Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib


locale:

[1] C/UTF-8/C/C/C/C


attached base packages:

[1] parallel  stats graphics  grDevices utils datasets  methods

[8] base


other attached packages:

[1] rugarch_1.4-9


loaded via a namespace (and not attached):

 [1] Rcpp_1.0.9  mclust_6.0.0

 [3] lattice_0.20-45 mvtnorm_1.1-3

 [5] zoo_1.8-12  MASS_7.3-58.1

 [7] GeneralizedHyperbolic_0.8-4 truncnorm_1.0-9

 [9] grid_4.2.2  pracma_2.4.2

[11] KernSmooth_2.23-20  SkewHyperbolic_0.4-0

[13] Matrix_1.5-1xts_0.12.1

[15] spd_2.0-1   tools_4.2.2

[17] ks_1.14.1   numDeriv_2016.8-1.1

[19] compiler_4.2.2  DistributionUtils_0.6-1

[21] Rsolnp_1.16

__
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] Could you manually replicate execution of a R function

2023-09-19 Thread Brian Smith
Hi,

I have trying to replicate a function from rugarch package manually.
Below is the calculation based on the function,

library(rugarch)
data(dji30ret)
spec = ugarchspec(mean.model = list(armaOrder = c(1,1), include.mean = TRUE),
variance.model = list(model = "gjrGARCH"), distribution.model = "sstd")
fit = ugarchfit(spec, data = dji30ret[1:1000, 1, drop = FALSE])
spec2 = spec
setfixed(spec2)<-as.list(coef(fit))
filt = ugarchfilter(spec2, dji30ret[1001:2500, 1, drop = FALSE], n.old = 1000)
actual = dji30ret[1001:2500,1]
# location+scale invariance allows to use [mu + sigma*q(p,0,1,skew,shape)]
VaR = fitted(filt) + sigma(filt)*qdist("sstd", p=0.05, mu = 0, sigma = 1,
skew = coef(fit)["skew"], shape=coef(fit)["shape"])
alpha = 0.05
conf.level = 0.95

VaRDurTest(0.05, actual, VaR)$b ## 1.019356


Now I want to replicate the calculation manually as below,


VaR.ind = ifelse(actual < VaR, 1, 0)
N = sum(VaR.ind)
TN = length(VaR.ind)
D = diff(which(VaR.ind == 1))
C = rep(0, length(D))
N = length(D)

pweibull = function (D, a, b, survival = FALSE)
{
cdf = 1 - exp(-(a * D)^b)
if (survival)
cdf = 1 - cdf
return(cdf)
}
dweibull = function (D, a, b, log = FALSE)
{
pdf = (b * log(a) + log(b) + (b - 1) * log(D) - (a * D)^b)
if (!log)
pdf = exp(pdf)
return(pdf)
}
likDurationW = function (pars, D, C, N)
{
b = pars[1]
a = ((N - C[1] - C[N])/(sum(D^b)))^(1/b)
lik = C[1] * log(pweibull(D[1], a, b, survival = TRUE)) +
(1 - C[1]) * dweibull(D[1], a, b, log = TRUE) + sum(dweibull(D[2:(N -
1)], a, b, log = TRUE)) + C[N] * log(pweibull(D[N],
a, b, survival = TRUE)) + (1 - C[N]) * dweibull(D[N],
a, b, log = TRUE)
if (!is.finite(lik) || is.nan(lik))
lik = 100
else lik = -lik
return(lik)
}
optim(par = 2, fn = likDurationW, gr = NULL, D = D, C = C, N = N,
method = "L-BFGS-B", lower = 0.001, upper = 10, control = list(trace =
0))$par  ## 1.029628

I fail to understand why there has to be a difference. Could you
please help to find the reason?

> sessionInfo()

R version 4.2.2 (2022-10-31)

Platform: x86_64-apple-darwin17.0 (64-bit)

Running under: macOS Big Sur ... 10.16


Matrix products: default

BLAS:   
/Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib

LAPACK: 
/Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib


locale:

[1] C/UTF-8/C/C/C/C


attached base packages:

[1] parallel  stats graphics  grDevices utils datasets  methods

[8] base


other attached packages:

[1] rugarch_1.4-9


loaded via a namespace (and not attached):

 [1] Rcpp_1.0.9  mclust_6.0.0

 [3] lattice_0.20-45 mvtnorm_1.1-3

 [5] zoo_1.8-12  MASS_7.3-58.1

 [7] GeneralizedHyperbolic_0.8-4 truncnorm_1.0-9

 [9] grid_4.2.2  pracma_2.4.2

[11] KernSmooth_2.23-20  SkewHyperbolic_0.4-0

[13] Matrix_1.5-1xts_0.12.1

[15] spd_2.0-1   tools_4.2.2

[17] ks_1.14.1   numDeriv_2016.8-1.1

[19] compiler_4.2.2  DistributionUtils_0.6-1

[21] Rsolnp_1.16

__
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-22 Thread akshay kulkarni
Dear Jeff,
  I am indeed guilty of a highly inadvertent diction...I have 
to welcome your exhortations

Coming back to the point, I have read Avanced R by HAdley. But its all 
theory...and the present issue that I ran into is, possibly, a practical 
application of ALL that. For example, I never knew, and don't think that it is 
ever mentioned in Avanced R, that, as Bill advised, to use the function with() 
to get the source code of java_check()...(caveat: if it is mentioned in 
Advanced R, please let me know the chapter and page number so that I can have a 
look...). And to get on the path to solve these practical problems, my first 
choice is R Help Mailing list! Therefore, a hearty thanks for your pointed 
answer and more importantly, your exhortations!

Thanking you,
Yours sincerely
AKSHAY M KULKARNI


From: Jeff Newmiller 
Sent: Friday, January 20, 2023 11:29 PM
To: r-help@r-project.org ; akshay kulkarni 
; Jorgen Harmse ; r-help@r-project.org 
; williamwdun...@gmail.com 
Subject: Re: [R] function doesn't exists but still runs. (akshay kulkarni)

This is not a "problem" ... it is a "feature". Packages often use functions 
from other packages, but that does NOT mean that you as a user can 
automatically use those functions  also.

If Package A uses Package B to implement something, but Package B becomes 
unavailable, the maintainer of Package A would like to fill in the gap. If 
Package A "Depends" on Package B then users of package A automatically get 
access to Package B and they get used to treating Package A like it contains 
all of the functions in Package B directly.

Therefore it is common to have Package A "Import" Package B so that the Package 
A maintainer won't have to re-implement all of Package B to avoid breaking code 
for users of Package A. They can fix things under the hood for their own 
Package A functions using other code.

If a user wants to depend on Package B, it is up to them to use the library 
function to do so explicitly... and when Package B goes away, they are 
responsible for dealing with that mess themselves.

You asked "how", and got answers... but you didn't bother to follow up on those 
answers by reading things like "Writing R Extensions" or Hadley Wickham's "R 
Packages" or "Advanced R". Don't turn that laziness into a value judgement 
about "problems" with R.

On January 20, 2023 9:18:54 AM PST, akshay kulkarni  
wrote:
>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 

Re: [R] function doesn't exists but still runs..... (akshay kulkarni)

2023-01-20 Thread Jeff Newmiller
This is not a "problem" ... it is a "feature". Packages often use functions 
from other packages, but that does NOT mean that you as a user can 
automatically use those functions  also.

If Package A uses Package B to implement something, but Package B becomes 
unavailable, the maintainer of Package A would like to fill in the gap. If 
Package A "Depends" on Package B then users of package A automatically get 
access to Package B and they get used to treating Package A like it contains 
all of the functions in Package B directly.

Therefore it is common to have Package A "Import" Package B so that the Package 
A maintainer won't have to re-implement all of Package B to avoid breaking code 
for users of Package A. They can fix things under the hood for their own 
Package A functions using other code.

If a user wants to depend on Package B, it is up to them to use the library 
function to do so explicitly... and when Package B goes away, they are 
responsible for dealing with that mess themselves.

You asked "how", and got answers... but you didn't bother to follow up on those 
answers by reading things like "Writing R Extensions" or Hadley Wickham's "R 
Packages" or "Advanced R". Don't turn that laziness into a value judgement 
about "problems" with R.

On January 20, 2023 9:18:54 AM PST, akshay kulkarni  
wrote:
>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
>

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

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

2023-01-20 Thread akshay kulkarni
Dear Greg,
  THanks for a very well pointed answer.

THanking you,
yours sincerely
AKSHAY M KULKARNI

From: Greg Snow <538...@gmail.com>
Sent: Friday, January 20, 2023 10:28 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] function doesn't exists but still runs.

A little simpler answer than the others.

Look at package Namespaces.  When a package is created, the NAMESPACE
file defines which functions in the package are exported (i.e.
available for you to use), the other functions are "private" to the
package meaning that other functions in the package can call those
functions, but they are not meant to be called directly by the user.

So in your case, the `selenium` function was exported, but
`java_check` was not exported.  The function does exist, but R's
regular search rules do not find it when you try to call it directly
(but because it shares the Namespace with selenium, it is found when
called there).

It is possible to call non-exported functions (use something like
RSelenium:::java_check()), but non-exported functions are not usually
documented and subject to change without any warning.  You are using
the functionality in a way different from how the author intended, so
there are no guarantees that it will do what you think it should.

On Thu, Jan 19, 2023 at 3: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/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 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

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

2023-01-20 Thread Greg Snow
A little simpler answer than the others.

Look at package Namespaces.  When a package is created, the NAMESPACE
file defines which functions in the package are exported (i.e.
available for you to use), the other functions are "private" to the
package meaning that other functions in the package can call those
functions, but they are not meant to be called directly by the user.

So in your case, the `selenium` function was exported, but
`java_check` was not exported.  The function does exist, but R's
regular search rules do not find it when you try to call it directly
(but because it shares the Namespace with selenium, it is found when
called there).

It is possible to call non-exported functions (use something like
RSelenium:::java_check()), but non-exported functions are not usually
documented and subject to change without any warning.  You are using
the functionality in a way different from how the author intended, so
there are no guarantees that it will do what you think it should.

On Thu, Jan 19, 2023 at 3: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/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 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] function doesn't exists but still runs..... (akshay kulkarni)

2023-01-20 Thread Jorgen Harmse via R-help
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/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 mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
&g

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

2023-01-19 Thread Bill Dunlap
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/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 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] function doesn't exists but still runs.....

2023-01-19 Thread akshay kulkarni
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 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 for Distribution Fitting

2022-10-26 Thread Ebert,Timothy Aaron
If you have three values, then it should be possible to fit any number of 
distributions such that they could return those three values. On the other 
hand, if you have billions of values and insist on a perfect fit then you may 
have a unique distribution only identified by the data in hand. For most 
purposes it is better to define the distribution based on your understanding of 
the numbers and how they were generated rather than trying to identify the 
distribution that best matches your data. I do not know your application for 
this. Here is a list of available functions in R:
https://cran.r-project.org/web/views/Distributions.html

I hope that helps, but I am not sure this is a task worth doing. If you start 
at the top of the list, and stop at the first "match" that sounds a bit like 
p-hacking.

Tim

-Original Message-
From: R-help  On Behalf Of JRG via R-help
Sent: Wednesday, October 26, 2022 10:01 AM
To: r-help@r-project.org
Subject: Re: [R] Function for Distribution Fitting

[External Email]

"all possible probability distributions"

I doubt that is a finite set.  To select "a bunch of them" would seem to imply 
a reduction of that set based on what's possible/promising/pertinent in your 
specific problem.  IMHO, what's the "most suitable distribution" tends to 
depend partly on knowledge of the subject matter of your problem.

Doesn't that put you back in your present situation?



---JRG




On 10/26/22 09:41, Paul Bernal wrote:
> Dear friends from the R community,
>
> Hope you are all doing great. So far, whenever I need to perform 
> distribution fitting on a particular dataset, I make use of R package 
> fitdistrplus.
>
> However, distribution fitting using the fitdist() function from 
> fitdistrplus is rather manual (you need to specify which probability 
> distribution you are trying to fit), and it would be more convenient 
> if the function tested all possible probability distributions (or a 
> bunch of them) and then estimates the parameters and suggests the most 
> suitable distribution.
>
> Is there any package besides fitdistrplus that does allow automatic 
> distribution fitting?
>
> Best regards,
> Paul
>
>   [[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-help&data=05%7C01%7Ctebert%40ufl
> .edu%7Cf7aa511782ff4d98a04908dab75aa2a0%7C0d4da0f84a314d76ace60a62331e
> 1b84%7C0%7C0%7C638023897166448945%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4w
> LjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C
> &sdata=XS069Wk8JxeT4piBqA5JC3vtE2vu6uS8KTp1tqDIf7c%3D&reserved
> =0 PLEASE do read the posting guide 
> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r
> -project.org%2Fposting-guide.html&data=05%7C01%7Ctebert%40ufl.edu%
> 7Cf7aa511782ff4d98a04908dab75aa2a0%7C0d4da0f84a314d76ace60a62331e1b84%
> 7C0%7C0%7C638023897166448945%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwM
> DAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&
> sdata=FZHNApQa2raJnbAgUZ544bH91EMtjSG7Ef47dMCoo3M%3D&reserved=0
> and provide commented, minimal, self-contained, reproducible code.

__
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-help&data=05%7C01%7Ctebert%40ufl.edu%7Cf7aa511782ff4d98a04908dab75aa2a0%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638023897166448945%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=XS069Wk8JxeT4piBqA5JC3vtE2vu6uS8KTp1tqDIf7c%3D&reserved=0
PLEASE do read the posting guide 
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7Ctebert%40ufl.edu%7Cf7aa511782ff4d98a04908dab75aa2a0%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638023897166448945%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=FZHNApQa2raJnbAgUZ544bH91EMtjSG7Ef47dMCoo3M%3D&reserved=0
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] Function for Distribution Fitting

2022-10-26 Thread Gabor Grothendieck
A Cullen & Frey graph (fitdistrplus::descdist) can be used to compare certain
common distributions.

On Wed, Oct 26, 2022 at 9:42 AM Paul Bernal  wrote:
>
> Dear friends from the R community,
>
> Hope you are all doing great. So far, whenever I need to perform
> distribution fitting on a particular dataset, I make use of R package
> fitdistrplus.
>
> However, distribution fitting using the fitdist() function from
> fitdistrplus is rather manual (you need to specify which probability
> distribution you are trying to fit), and it would be more convenient if the
> function tested all possible probability distributions (or a bunch of them)
> and then estimates the parameters and suggests the most suitable
> distribution.
>
> Is there any package besides fitdistrplus that does allow automatic
> distribution fitting?
>
> Best regards,
> Paul
>
> [[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.



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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] Function for Distribution Fitting

2022-10-26 Thread Bert Gunter
Of course it's an infinite set!

The OP should look here:
https://cran.r-project.org/web/views/Distributions.html

-- Bert

On Wed, Oct 26, 2022 at 7:01 AM JRG via R-help  wrote:
>
> "all possible probability distributions"
>
> I doubt that is a finite set.  To select "a bunch of them" would seem to
> imply a reduction of that set based on what's
> possible/promising/pertinent in your specific problem.  IMHO, what's the
> "most suitable distribution" tends to depend partly on knowledge of the
> subject matter of your problem.
>
> Doesn't that put you back in your present situation?
>
>
>
> ---JRG
>
>
>
>
> On 10/26/22 09:41, Paul Bernal wrote:
> > Dear friends from the R community,
> >
> > Hope you are all doing great. So far, whenever I need to perform
> > distribution fitting on a particular dataset, I make use of R package
> > fitdistrplus.
> >
> > However, distribution fitting using the fitdist() function from
> > fitdistrplus is rather manual (you need to specify which probability
> > distribution you are trying to fit), and it would be more convenient if the
> > function tested all possible probability distributions (or a bunch of them)
> > and then estimates the parameters and suggests the most suitable
> > distribution.
> >
> > Is there any package besides fitdistrplus that does allow automatic
> > distribution fitting?
> >
> > Best regards,
> > Paul
> >
> >   [[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-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 for Distribution Fitting

2022-10-26 Thread JRG via R-help
"all possible probability distributions"

I doubt that is a finite set.  To select "a bunch of them" would seem to
imply a reduction of that set based on what's
possible/promising/pertinent in your specific problem.  IMHO, what's the
"most suitable distribution" tends to depend partly on knowledge of the
subject matter of your problem.

Doesn't that put you back in your present situation?



---JRG




On 10/26/22 09:41, Paul Bernal wrote:
> Dear friends from the R community,
>
> Hope you are all doing great. So far, whenever I need to perform
> distribution fitting on a particular dataset, I make use of R package
> fitdistrplus.
>
> However, distribution fitting using the fitdist() function from
> fitdistrplus is rather manual (you need to specify which probability
> distribution you are trying to fit), and it would be more convenient if the
> function tested all possible probability distributions (or a bunch of them)
> and then estimates the parameters and suggests the most suitable
> distribution.
>
> Is there any package besides fitdistrplus that does allow automatic
> distribution fitting?
>
> Best regards,
> Paul
>
>   [[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] Function for Distribution Fitting

2022-10-26 Thread Paul Bernal
Dear friends from the R community,

Hope you are all doing great. So far, whenever I need to perform
distribution fitting on a particular dataset, I make use of R package
fitdistrplus.

However, distribution fitting using the fitdist() function from
fitdistrplus is rather manual (you need to specify which probability
distribution you are trying to fit), and it would be more convenient if the
function tested all possible probability distributions (or a bunch of them)
and then estimates the parameters and suggests the most suitable
distribution.

Is there any package besides fitdistrplus that does allow automatic
distribution fitting?

Best regards,
Paul

[[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 problem: multi selection in one argument

2022-01-25 Thread Martin Maechler
>>>>> Rui Barradas 
>>>>> on Tue, 25 Jan 2022 14:22:47 + writes:

> Hello,
> Here are 3 functions that do what the question asks for. The first 2 are 
> tidyverse solutions, the last one a base R function.

> I don't understand why the group_by and mutate, that's why I've included 
> a 2nd tidyverse function. And the base R function follows the same lines 
> of outputing the table only without data transformation.

> And the test dataset is not iris, it only has one factor variable. It 
> doesn't make sense to table a continuous variable such as Petal.Width.

> The data set mtcars has several numeric variables that are in fact 
> categorical ("vs", "am") and one, "cyl", that can be tabled. The 
> examples below use mtcars.



> f3 <- function(data, ...){
>   groups <- unlist(list(...))
>   temp <- data %>%
> select(all_of({{groups}})) %>%
> group_by(across(all_of({{groups}}))) %>%
> mutate(numbering = row_number(), max = n())
>   temp %>%
> select(all_of({{groups}})) %>%
> table()
> }

> f4 <- function(data, ...){
>   groups <- unlist(list(...))
>   data %>%
> select(all_of({{groups}})) %>%
> table()
> }

> f5 <- function(data, ...){
>   temp <- lapply(list(...), \(col) data[[col]])
>   table(setNames(temp, list(...)))
> }

> f3(mtcars, "am", "cyl")
> f4(mtcars, "am", "cyl")
> f5(mtcars, "am", "cyl")

> Hope this helps,
> Rui Barradas

Thank you, Rui!

Note that your base R solution can be vastly simplified :

> f6 <- function(data, ...) table(data[, unlist(list(...))])
> f6(mtcars, "am", "cyl")
   cyl
am   4  6  8
  0  3  4 12
  1  8  3  2
> 

If you started measuring carefully, I'm sure this would not only
be the shortest but also by far the fastest solution ...

Best,
Martin

--
Martin Maechler
ETH Zurich  and   R Core Team


> Às 00:14 de 25/01/2022, Kai Yang via R-help escreveu:
>> Hello Team,
>> I can run the function below:
>> 
>> library(tidyverse)
>> 
>> f2 <- function(indata, subgrp1){
>>   indata0 <- indata
>>   temp<- indata0 %>% select({{subgrp1}}) %>% arrange({{subgrp1}}) %>%
>> group_by({{subgrp1}}) %>%
>> mutate(numbering =row_number(), max=max(numbering))
>>   view(temp)
>>   f_table <- table(temp$Species)
>>   view(f_table)
>>   return(f_table)
>> }
>> f2(iris, Species)
>> 
>> You can see the second argument I use Species only, and it works fine.
>> But If I say, I want the 2nd argument = Petal.Width, Species , how 
should I write the argument? I did try f2(iris, c(Petal.Width, Species)), but I 
got error message:
>> Error: arrange() failed at implicit mutate() step.
>> * Problem with `mutate()` column `..1`.
>> i `..1 = c(Petal.Width, Species)`.
>> i `..1` must be size 150 or 1, not 300.
>> 
>> I'm not sure how to fix the problem either in function or can fix it 
when using the function.
>> Thank you,
>> Kai
>> [[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-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 problem: multi selection in one argument

2022-01-25 Thread Rui Barradas

Hello,

Here are 3 functions that do what the question asks for. The first 2 are 
tidyverse solutions, the last one a base R function.


I don't understand why the group_by and mutate, that's why I've included 
a 2nd tidyverse function. And the base R function follows the same lines 
of outputing the table only without data transformation.


And the test dataset is not iris, it only has one factor variable. It 
doesn't make sense to table a continuous variable such as Petal.Width.


The data set mtcars has several numeric variables that are in fact 
categorical ("vs", "am") and one, "cyl", that can be tabled. The 
examples below use mtcars.




f3 <- function(data, ...){
  groups <- unlist(list(...))
  temp <- data %>%
    select(all_of({{groups}})) %>%
    group_by(across(all_of({{groups}}))) %>%
    mutate(numbering = row_number(), max = n())
  temp %>%
    select(all_of({{groups}})) %>%
    table()
}

f4 <- function(data, ...){
  groups <- unlist(list(...))
  data %>%
    select(all_of({{groups}})) %>%
    table()
}

f5 <- function(data, ...){
  temp <- lapply(list(...), \(col) data[[col]])
  table(setNames(temp, list(...)))
}

f3(mtcars, "am", "cyl")
f4(mtcars, "am", "cyl")
f5(mtcars, "am", "cyl")


Hope this helps,

Rui Barradas

Às 00:14 de 25/01/2022, Kai Yang via R-help escreveu:

Hello Team,
I can run the function below:

library(tidyverse)

f2 <- function(indata, subgrp1){
   indata0 <- indata
   temp    <- indata0 %>% select({{subgrp1}}) %>% arrange({{subgrp1}}) %>%
     group_by({{subgrp1}}) %>%
     mutate(numbering =row_number(), max=max(numbering))
   view(temp)
   f_table <- table(temp$Species)
   view(f_table)
   return(f_table)
}
f2(iris, Species)

You can see the second argument I use Species only, and it works fine.
But If I say, I want the 2nd argument = Petal.Width, Species , how should I 
write the argument? I did try f2(iris, c(Petal.Width, Species)), but I got 
error message:
Error: arrange() failed at implicit mutate() step.
* Problem with `mutate()` column `..1`.
i `..1 = c(Petal.Width, Species)`.
i `..1` must be size 150 or 1, not 300.

I'm not sure how to fix the problem either in function or can fix it when using 
the function.
Thank you,
Kai
[[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] function problem: multi selection in one argument

2022-01-25 Thread PIKAL Petr
Hallo

You should explain better what do you want as many people here do not use 
tidyverse functions.

I am not sure what the function should do.
table(iris$Species)
give the same result and whatever you do in tidyverse part it always finalise 
in table(...$Species)

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Kai Yang via R-help
> Sent: Tuesday, January 25, 2022 1:14 AM
> To: R-help Mailing List 
> Subject: [R] function problem: multi selection in one argument
>
> Hello Team,
> I can run the function below:
>
> library(tidyverse)
>
> f2 <- function(indata, subgrp1){
>   indata0 <- indata
>   temp<- indata0 %>% select({{subgrp1}}) %>% arrange({{subgrp1}}) %>%
> group_by({{subgrp1}}) %>%
> mutate(numbering =row_number(), max=max(numbering))
>   view(temp)
>   f_table <- table(temp$Species)
>   view(f_table)
>   return(f_table)
> }
> f2(iris, Species)
>
> You can see the second argument I use Species only, and it works fine. But 
> If I
> say, I want the 2nd argument = Petal.Width, Species , how should I write the
> argument? I did try f2(iris, c(Petal.Width, Species)), but I got error 
> message:
> Error: arrange() failed at implicit mutate() step.
> * Problem with `mutate()` column `..1`.
> i `..1 = c(Petal.Width, Species)`.
> i `..1` must be size 150 or 1, not 300.
>
> I'm not sure how to fix the problem either in function or can fix it when 
> using the
> function.
> Thank you,
> Kai
>   [[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] function problem: multi selection in one argument

2022-01-24 Thread Kai Yang via R-help
Hello Team,
I can run the function below:

library(tidyverse)

f2 <- function(indata, subgrp1){
  indata0 <- indata
  temp    <- indata0 %>% select({{subgrp1}}) %>% arrange({{subgrp1}}) %>% 
    group_by({{subgrp1}}) %>%
    mutate(numbering =row_number(), max=max(numbering))
  view(temp)
  f_table <- table(temp$Species)
  view(f_table)
  return(f_table)
}
f2(iris, Species)

You can see the second argument I use Species only, and it works fine. 
But If I say, I want the 2nd argument = Petal.Width, Species , how should I 
write the argument? I did try f2(iris, c(Petal.Width, Species)), but I got 
error message:
Error: arrange() failed at implicit mutate() step. 
* Problem with `mutate()` column `..1`.
i `..1 = c(Petal.Width, Species)`.
i `..1` must be size 150 or 1, not 300.

I'm not sure how to fix the problem either in function or can fix it when using 
the function.
Thank you,
Kai
[[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] R Function question, (repost to fix the messy work format)

2021-07-02 Thread Eric Berger
Definitely doable and you are on the right path and maybe even close.
The error message you got showed your query as having the wrong info after
the 'FROM'
keyword

 ' SELECT * FROM c("BIODBX.MECCUNIQUE2", "BIODBX.QDATA_HTML_DUMMY",
"BIODBX.SET_ITEMS", "BIODBX.SET_NAMES", "dbo.sysdiagrams",
"GEMD.ASSAY_DEFINITIONS",

etc

i.e you are passing the full vector of table names and not a single one
(the first being the one specified in your working example)

You have to figure out how to correctly set up your loop on this vector of
table names.
The debugger - browser() - is your friend! Learn how to use it, as I
suggested before.



...



On Fri, Jul 2, 2021 at 10:47 PM Kai Yang  wrote:

> Hi Eric,
>
> Thank you spent time to help me for this.
>
>
> Here is the thing: I was requested to manage a sql server for my group.
> the server has many schemas and the tables (>200). I use ODBC to connect
> the server and get the schema name + table name into a data frame.
>
>
> For each of schema + table on server, I need to run a summary report. So I
> wrote a summary script like this:
>
>
> res <- dbGetQuery(con, "SELECT * FROM BIODBX.MECCUNIQUE2")
>
> view(dfSummary(res), file =
> "W:/project/_Joe.B/MSSQL/try/summarytools.BIODBX.MECCUNIQUE2.html")
>
> rm(res)
>
>
> the script works well. but I don't want to write 200+ times of the script
> to summary each table. So, I'm trying to write the function to do this.
> this is my goal.
>
>
> First of all, I'm not sure if this is the right way to do the summary
> report, because I'm a new R user. So please correct me if my idea is doable.
>
>
> Second, would you please tell me what is "more detail" information do you
> need?
>
>
> Thank you,
>
> Kai
>
>
>
> On Friday, July 2, 2021, 12:31:17 PM PDT, Eric Berger <
> ericjber...@gmail.com> wrote:
>
>
> Hard for me to tell without more details but it looks like the following
> has several bugs
>
> for (i in dbtable$Tot_table)
> {
>   Tabname <- as.character(sqldf(sprintf("SELECT Tot_table FROM dbtable",
> i)))
>   summ(Tabname)
> }
>
> Your sprintf() statement seems to use 'i' but actually does not.
> You probably want to rewrite/rearrange this code. More like
>
> x <- sqldf("SELECT Tot_table FROM dbtable")
> for ( Tabname in x )
> summ(Tabname)
>
> no doubt this is wrong but put a browser() call after the x <- sqldf(...)
> line and inspect x and go from there
>
>
>
>
> On Fri, Jul 2, 2021 at 10:20 PM Kai Yang  wrote:
>
> Hello Eric,
>
> Following your suggestion, I modified the code as:
>
> summ <- function(Tabname){
>
>   query <- sprintf(" SELECT * FROM %s",Tabname)
>
>   res <- dbGetQuery(con, query)
>
>   view(dfSummary(res), file =
> "W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")
>
>   rm(res)
>
> }
>
>
> for (i in dbtable$Tot_table)
>
> {
>
>   Tabname <- as.character(sqldf(sprintf("SELECT Tot_table FROM dbtable",
> i)))
>
>   summ(Tabname)
>
> }
>
> after submitted the work, I got the error message below:
>
>
>  Error: nanodbc/nanodbc.cpp:1655: 42000: [Microsoft][ODBC Driver 17 for
> SQL Server][SQL Server]Invalid object name 'c'.  [Microsoft][ODBC Driver 17
> for SQL Server][SQL Server]Statement(s) could not be prepared.
>  ' SELECT * FROM c("BIODBX.MECCUNIQUE2", "BIODBX.QDATA_HTML_DUMMY",
> "BIODBX.SET_ITEMS", "BIODBX.SET_NAMES", "dbo.sysdiagrams",
> "GEMD.ASSAY_DEFINITIONS", "GEMD.ASSAY_DISCRETE_VALUES",
> "GEMD.ASSAY_QUESTIONS", "GEMD.ASSAY_RUNS", "GEMD.BIODBX_DATABASE_SEED",
> "GEMD.BIODBX_USER_SEEDS", "GEMD.BIODBX_USERS", "GEMD.DATA_ENTRY_PAGES",
> "GEMD.DISC_SESSION_QID", "GEMD.DISC_SESSION_STATUS",
> "GEMD.DISC_SESSION_TYPE", "GEMD.DISCREPANCIES",
> "GEMD.DISCREPANCY_QUERY_TEMP", "GEMD.DISCRETE_VALUES",
> "GEMD.ENTERED_DATA_ENTRY_PAGES", "GEMD.ENTRY_GROUPS",
> "GEMD.ExportSampleListNames", "GEMD.FORM_STATUS_BY_SUBJECT",
> "GEMD.GEMD_CODELIST_GROUPS", "GEMD.GEMD_CODELIST_VALUES",
> "GEMD.GEMD_LOT_DEFINITIONS", "GEMD.GEMD_SAMPLES", "GEMD.GEMD_STUDIES",
> "GEMD.MECCUNIQUE", "GEMD.MECCUNIQUE2", "GEMD.MISSING_DI
>
>
> One more question,  in the code of "*view(dfSummary(res), file =
> "W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")*",
>
> can Tabname part be replacted automatic also?
>
> Thank you,
>
> Kai
> On Friday, July 2, 2021, 12:06:12 PM PDT, Eric Berger <
> ericjber...@gmail.com> wrote:
>
>
> Modify the summ() function to start like this
>
> summ <- function(Tabname){
>query <- sprintf(" SELECT * FROM %s",Tabname)
>   res <- dbGetQuery(con, query)
>
> etc
>
> HTH,
> Eric
>
> On Fri, Jul 2, 2021 at 9:39 PM Kai Yang via R-help 
> wrote:
>
> Hello List,
>
> The previous post look massy. I repost my question. Sorry,
>
>
> I need to generate summary report for many tables (>200 tables). For each
> table, I can use the script to generate report:
> res <- dbGetQuery(con, "SELECT * FROM BIODBX.MECCUNIQUE2")
> view(dfSummary(res), file =
> "W:/project/_Joe.B/MSSQL/try/summarytools.BIODBX.MECCUNIQUE2.html")
> rm(res)
> BIODBX.MECCUNIQUE2 is the name of table.
>
> I have all of tables' name in a data 

Re: [R] R Function question, (repost to fix the messy work format)

2021-07-02 Thread Kai Yang via R-help
 Hi Eric,
Thank you spent time to help me for this.

Here is the thing: I was requested to manage a sql server for my group. the 
server has many schemas and the tables (>200). I use ODBC to connect the server 
and get the schema name + table name into a data frame.

For each of schema + table on server, I need to run a summary report. So I 
wrote a summary script like this:

res <- dbGetQuery(con, "SELECT * FROM BIODBX.MECCUNIQUE2")
view(dfSummary(res), file = 
"W:/project/_Joe.B/MSSQL/try/summarytools.BIODBX.MECCUNIQUE2.html")
rm(res)

the script works well. but I don't want to write 200+ times of the script to 
summary each table. So, I'm trying to write the function to do this. this is my 
goal.

First of all, I'm not sure if this is the right way to do the summary report, 
because I'm a new R user. So please correct me if my idea is doable.

Second, would you please tell me what is "more detail" information do you need?

Thank you,
Kai


On Friday, July 2, 2021, 12:31:17 PM PDT, Eric Berger 
 wrote:  
 
 Hard for me to tell without more details but it looks like the following has 
several bugs
for (i in dbtable$Tot_table){
  Tabname <- as.character(sqldf(sprintf("SELECT Tot_table FROM dbtable", i)))
  summ(Tabname)
}

Your sprintf() statement seems to use 'i' but actually does not.You probably 
want to rewrite/rearrange this code. More like
x <- sqldf("SELECT Tot_table FROM dbtable")for ( Tabname in x )summ(Tabname)
no doubt this is wrong but put a browser() call after the x <- sqldf(...)line 
and inspect x and go from there



On Fri, Jul 2, 2021 at 10:20 PM Kai Yang  wrote:

 Hello Eric,
Following your suggestion, I modified the code as:
summ <- function(Tabname){
  query <- sprintf(" SELECT * FROM %s",Tabname)
  res <- dbGetQuery(con, query)
  view(dfSummary(res), file = 
"W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")
  rm(res)
}

for (i in dbtable$Tot_table)
{
  Tabname <- as.character(sqldf(sprintf("SELECT Tot_table FROM dbtable", i)))
  summ(Tabname)
}
after submitted the work, I got the error message below:

 Error: nanodbc/nanodbc.cpp:1655: 42000: [Microsoft][ODBC Driver 17 for SQL 
Server][SQL Server]Invalid object name 'c'.  [Microsoft][ODBC Driver 17 for SQL 
Server][SQL Server]Statement(s) could not be prepared.  ' SELECT * FROM 
c("BIODBX.MECCUNIQUE2", "BIODBX.QDATA_HTML_DUMMY", "BIODBX.SET_ITEMS", 
"BIODBX.SET_NAMES", "dbo.sysdiagrams", "GEMD.ASSAY_DEFINITIONS", 
"GEMD.ASSAY_DISCRETE_VALUES", "GEMD.ASSAY_QUESTIONS", "GEMD.ASSAY_RUNS", 
"GEMD.BIODBX_DATABASE_SEED", "GEMD.BIODBX_USER_SEEDS", "GEMD.BIODBX_USERS", 
"GEMD.DATA_ENTRY_PAGES", "GEMD.DISC_SESSION_QID", "GEMD.DISC_SESSION_STATUS", 
"GEMD.DISC_SESSION_TYPE", "GEMD.DISCREPANCIES", "GEMD.DISCREPANCY_QUERY_TEMP", 
"GEMD.DISCRETE_VALUES", "GEMD.ENTERED_DATA_ENTRY_PAGES", "GEMD.ENTRY_GROUPS", 
"GEMD.ExportSampleListNames", "GEMD.FORM_STATUS_BY_SUBJECT", 
"GEMD.GEMD_CODELIST_GROUPS", "GEMD.GEMD_CODELIST_VALUES", 
"GEMD.GEMD_LOT_DEFINITIONS", "GEMD.GEMD_SAMPLES", "GEMD.GEMD_STUDIES", 
"GEMD.MECCUNIQUE", "GEMD.MECCUNIQUE2", "GEMD.MISSING_DI 

One more question,  in the code of "view(dfSummary(res), file = 
"W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")",
can Tabname part be replacted automatic also? 
Thank you,
KaiOn Friday, July 2, 2021, 12:06:12 PM PDT, Eric Berger 
 wrote:  
 
 Modify the summ() function to start like this 
summ <- function(Tabname){   query <- sprintf("SELECT * FROM %s",Tabname)
  res <- dbGetQuery(con, query)
 
etc
HTH,Eric
On Fri, Jul 2, 2021 at 9:39 PM Kai Yang via R-help  wrote:

Hello List,

The previous post look massy. I repost my question. Sorry,


I need to generate summary report for many tables (>200 tables). For each 
table, I can use the script to generate report:
res <- dbGetQuery(con, "SELECT * FROM BIODBX.MECCUNIQUE2")
view(dfSummary(res), file = 
"W:/project/_Joe.B/MSSQL/try/summarytools.BIODBX.MECCUNIQUE2.html")
rm(res)
BIODBX.MECCUNIQUE2 is the name of table.

I have all of tables' name in a data frame. So, I'm trying to write a function 
to do this:
summ <- function(Tabname){
  res <- dbGetQuery(con, "SELECT * FROM Tabname")
  view(dfSummary(res), file = 
"W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")
  rm(res)
}
for (i in dbtable$Tot_table)
{
  Tabname <- as.character(sqldf(sprintf("SELECT Tot_table FROM dbtable", i)))
  summ(Tabname)
}

1. I created  a function summ, the argument is Tabname. I put the Tabname in 
the function. I hope it can be replaced one by one
2. the table dbtable contents all tables' name (>200 rows), the field name is 
Tot_table
3. I want use "for" to establish a loop, which can automatic generate a summary 
report for each table

but I got error message below:
 Error: nanodbc/nanodbc.cpp:1655: 42000: [Microsoft][ODBC Driver 17 for SQL 
Server][SQL Server]Invalid object name 'Tabname'.  
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be 
prepared. 

 'SELECT * FROM Tabname' 
10. stop(structure(list(message = 

Re: [R] R Function question, (repost to fix the messy work format)

2021-07-02 Thread Jeff Newmiller
Not all advice received on the Internet is safe.

https://xkcd.com/327

https://db.rstudio.com/best-practices/run-queries-safely

It is not that much more difficult to do it right.

On July 2, 2021 12:05:43 PM PDT, Eric Berger  wrote:
>Modify the summ() function to start like this
>
>summ <- function(Tabname){
>   query <- sprintf(" SELECT * FROM %s",Tabname)
>  res <- dbGetQuery(con, query)
>
>etc
>
>HTH,
>Eric
>
>On Fri, Jul 2, 2021 at 9:39 PM Kai Yang via R-help
>
>wrote:
>
>> Hello List,
>>
>> The previous post look massy. I repost my question. Sorry,
>>
>>
>> I need to generate summary report for many tables (>200 tables). For
>each
>> table, I can use the script to generate report:
>> res <- dbGetQuery(con, "SELECT * FROM BIODBX.MECCUNIQUE2")
>> view(dfSummary(res), file =
>> "W:/project/_Joe.B/MSSQL/try/summarytools.BIODBX.MECCUNIQUE2.html")
>> rm(res)
>> BIODBX.MECCUNIQUE2 is the name of table.
>>
>> I have all of tables' name in a data frame. So, I'm trying to write a
>> function to do this:
>> summ <- function(Tabname){
>>   res <- dbGetQuery(con, "SELECT * FROM Tabname")
>>   view(dfSummary(res), file =
>> "W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")
>>   rm(res)
>> }
>> for (i in dbtable$Tot_table)
>> {
>>   Tabname <- as.character(sqldf(sprintf("SELECT Tot_table FROM
>dbtable",
>> i)))
>>   summ(Tabname)
>> }
>>
>> 1. I created  a function summ, the argument is Tabname. I put the
>Tabname
>> in the function. I hope it can be replaced one by one
>> 2. the table dbtable contents all tables' name (>200 rows), the field
>name
>> is Tot_table
>> 3. I want use "for" to establish a loop, which can automatic generate
>a
>> summary report for each table
>>
>> but I got error message below:
>>  Error: nanodbc/nanodbc.cpp:1655: 42000: [Microsoft][ODBC Driver 17
>for
>> SQL Server][SQL Server]Invalid object name 'Tabname'.
>> [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s)
>could
>> not be prepared.
>>
>>  'SELECT * FROM Tabname'
>> 10. stop(structure(list(message = "nanodbc/nanodbc.cpp:1655: 42000:
>> [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid
>> object name 'Tabname'.  [Microsoft][ODBC Driver 17 for SQL
>Server][SQL
>> Server]Statement(s) could not be prepared. \n
>> 'SELECT * FROM Tabname'",
>> call = NULL, cppstack = NULL), class = c("odbc::odbc_error",
>> "C++Error", "error", "condition")))
>> 9.new_result(connection@ptr, statement, immediate)
>> 8.OdbcResult(connection = conn, statement = statement, params =
>params,
>>  immediate = immediate)
>> 7..local(conn, statement, ...)
>> 6.dbSendQuery(conn, statement, params = params, ...)
>> 5.dbSendQuery(conn, statement, params = params, ...)
>> 4..local(conn, statement, ...)
>> 3.dbGetQuery(con, "SELECT * FROM Tabname")
>> 2.dbGetQuery(con, "SELECT * FROM Tabname")
>> 1.summ(Tabname)
>>
>> it seems the tables' name is not successfully pass into query. can
>someone
>> give me an instruction for this?
>> many thanks,
>> Kai
>>
>>
>> [[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.

-- 
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] R Function question, (repost to fix the messy work format)

2021-07-02 Thread Eric Berger
Hard for me to tell without more details but it looks like the following
has several bugs

for (i in dbtable$Tot_table)
{
  Tabname <- as.character(sqldf(sprintf("SELECT Tot_table FROM dbtable",
i)))
  summ(Tabname)
}

Your sprintf() statement seems to use 'i' but actually does not.
You probably want to rewrite/rearrange this code. More like

x <- sqldf("SELECT Tot_table FROM dbtable")
for ( Tabname in x )
summ(Tabname)

no doubt this is wrong but put a browser() call after the x <- sqldf(...)
line and inspect x and go from there




On Fri, Jul 2, 2021 at 10:20 PM Kai Yang  wrote:

> Hello Eric,
>
> Following your suggestion, I modified the code as:
>
> summ <- function(Tabname){
>
>   query <- sprintf(" SELECT * FROM %s",Tabname)
>
>   res <- dbGetQuery(con, query)
>
>   view(dfSummary(res), file =
> "W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")
>
>   rm(res)
>
> }
>
>
> for (i in dbtable$Tot_table)
>
> {
>
>   Tabname <- as.character(sqldf(sprintf("SELECT Tot_table FROM dbtable",
> i)))
>
>   summ(Tabname)
>
> }
>
> after submitted the work, I got the error message below:
>
>
>  Error: nanodbc/nanodbc.cpp:1655: 42000: [Microsoft][ODBC Driver 17 for
> SQL Server][SQL Server]Invalid object name 'c'.  [Microsoft][ODBC Driver 17
> for SQL Server][SQL Server]Statement(s) could not be prepared.
>  ' SELECT * FROM c("BIODBX.MECCUNIQUE2", "BIODBX.QDATA_HTML_DUMMY",
> "BIODBX.SET_ITEMS", "BIODBX.SET_NAMES", "dbo.sysdiagrams",
> "GEMD.ASSAY_DEFINITIONS", "GEMD.ASSAY_DISCRETE_VALUES",
> "GEMD.ASSAY_QUESTIONS", "GEMD.ASSAY_RUNS", "GEMD.BIODBX_DATABASE_SEED",
> "GEMD.BIODBX_USER_SEEDS", "GEMD.BIODBX_USERS", "GEMD.DATA_ENTRY_PAGES",
> "GEMD.DISC_SESSION_QID", "GEMD.DISC_SESSION_STATUS",
> "GEMD.DISC_SESSION_TYPE", "GEMD.DISCREPANCIES",
> "GEMD.DISCREPANCY_QUERY_TEMP", "GEMD.DISCRETE_VALUES",
> "GEMD.ENTERED_DATA_ENTRY_PAGES", "GEMD.ENTRY_GROUPS",
> "GEMD.ExportSampleListNames", "GEMD.FORM_STATUS_BY_SUBJECT",
> "GEMD.GEMD_CODELIST_GROUPS", "GEMD.GEMD_CODELIST_VALUES",
> "GEMD.GEMD_LOT_DEFINITIONS", "GEMD.GEMD_SAMPLES", "GEMD.GEMD_STUDIES",
> "GEMD.MECCUNIQUE", "GEMD.MECCUNIQUE2", "GEMD.MISSING_DI
>
>
> One more question,  in the code of "*view(dfSummary(res), file =
> "W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")*",
>
> can Tabname part be replacted automatic also?
>
> Thank you,
>
> Kai
> On Friday, July 2, 2021, 12:06:12 PM PDT, Eric Berger <
> ericjber...@gmail.com> wrote:
>
>
> Modify the summ() function to start like this
>
> summ <- function(Tabname){
>query <- sprintf(" SELECT * FROM %s",Tabname)
>   res <- dbGetQuery(con, query)
>
> etc
>
> HTH,
> Eric
>
> On Fri, Jul 2, 2021 at 9:39 PM Kai Yang via R-help 
> wrote:
>
> Hello List,
>
> The previous post look massy. I repost my question. Sorry,
>
>
> I need to generate summary report for many tables (>200 tables). For each
> table, I can use the script to generate report:
> res <- dbGetQuery(con, "SELECT * FROM BIODBX.MECCUNIQUE2")
> view(dfSummary(res), file =
> "W:/project/_Joe.B/MSSQL/try/summarytools.BIODBX.MECCUNIQUE2.html")
> rm(res)
> BIODBX.MECCUNIQUE2 is the name of table.
>
> I have all of tables' name in a data frame. So, I'm trying to write a
> function to do this:
> summ <- function(Tabname){
>   res <- dbGetQuery(con, "SELECT * FROM Tabname")
>   view(dfSummary(res), file =
> "W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")
>   rm(res)
> }
> for (i in dbtable$Tot_table)
> {
>   Tabname <- as.character(sqldf(sprintf("SELECT Tot_table FROM dbtable",
> i)))
>   summ(Tabname)
> }
>
> 1. I created  a function summ, the argument is Tabname. I put the Tabname
> in the function. I hope it can be replaced one by one
> 2. the table dbtable contents all tables' name (>200 rows), the field name
> is Tot_table
> 3. I want use "for" to establish a loop, which can automatic generate a
> summary report for each table
>
> but I got error message below:
>  Error: nanodbc/nanodbc.cpp:1655: 42000: [Microsoft][ODBC Driver 17 for
> SQL Server][SQL Server]Invalid object name 'Tabname'.
> [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could
> not be prepared.
>
>  'SELECT * FROM Tabname'
> 10. stop(structure(list(message = "nanodbc/nanodbc.cpp:1655: 42000:
> [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid
> object name 'Tabname'.  [Microsoft][ODBC Driver 17 for SQL Server][SQL
> Server]Statement(s) could not be prepared. \n
> 'SELECT * FROM Tabname'",
> call = NULL, cppstack = NULL), class = c("odbc::odbc_error",
> "C++Error", "error", "condition")))
> 9.new_result(connection@ptr, statement, immediate)
> 8.OdbcResult(connection = conn, statement = statement, params = params,
>  immediate = immediate)
> 7..local(conn, statement, ...)
> 6.dbSendQuery(conn, statement, params = params, ...)
> 5.dbSendQuery(conn, statement, params = params, ...)
> 4..local(conn, statement, ...)
> 3.dbGetQuery(con, "SELECT * FROM Tabname")
> 2.dbGetQuery(con, "SELECT * FROM Tabname")
> 1.summ(Tabname)
>
> it seems the tabl

Re: [R] R Function question, (repost to fix the messy work format)

2021-07-02 Thread Kai Yang via R-help
 Hello Eric,
Following your suggestion, I modified the code as:
summ <- function(Tabname){
  query <- sprintf(" SELECT * FROM %s",Tabname)
  res <- dbGetQuery(con, query)
  view(dfSummary(res), file = 
"W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")
  rm(res)
}

for (i in dbtable$Tot_table)
{
  Tabname <- as.character(sqldf(sprintf("SELECT Tot_table FROM dbtable", i)))
  summ(Tabname)
}
after submitted the work, I got the error message below:

 Error: nanodbc/nanodbc.cpp:1655: 42000: [Microsoft][ODBC Driver 17 for SQL 
Server][SQL Server]Invalid object name 'c'.  [Microsoft][ODBC Driver 17 for SQL 
Server][SQL Server]Statement(s) could not be prepared.  ' SELECT * FROM 
c("BIODBX.MECCUNIQUE2", "BIODBX.QDATA_HTML_DUMMY", "BIODBX.SET_ITEMS", 
"BIODBX.SET_NAMES", "dbo.sysdiagrams", "GEMD.ASSAY_DEFINITIONS", 
"GEMD.ASSAY_DISCRETE_VALUES", "GEMD.ASSAY_QUESTIONS", "GEMD.ASSAY_RUNS", 
"GEMD.BIODBX_DATABASE_SEED", "GEMD.BIODBX_USER_SEEDS", "GEMD.BIODBX_USERS", 
"GEMD.DATA_ENTRY_PAGES", "GEMD.DISC_SESSION_QID", "GEMD.DISC_SESSION_STATUS", 
"GEMD.DISC_SESSION_TYPE", "GEMD.DISCREPANCIES", "GEMD.DISCREPANCY_QUERY_TEMP", 
"GEMD.DISCRETE_VALUES", "GEMD.ENTERED_DATA_ENTRY_PAGES", "GEMD.ENTRY_GROUPS", 
"GEMD.ExportSampleListNames", "GEMD.FORM_STATUS_BY_SUBJECT", 
"GEMD.GEMD_CODELIST_GROUPS", "GEMD.GEMD_CODELIST_VALUES", 
"GEMD.GEMD_LOT_DEFINITIONS", "GEMD.GEMD_SAMPLES", "GEMD.GEMD_STUDIES", 
"GEMD.MECCUNIQUE", "GEMD.MECCUNIQUE2", "GEMD.MISSING_DI 

One more question,  in the code of "view(dfSummary(res), file = 
"W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")",
can Tabname part be replacted automatic also? 
Thank you,
KaiOn Friday, July 2, 2021, 12:06:12 PM PDT, Eric Berger 
 wrote:  
 
 Modify the summ() function to start like this 
summ <- function(Tabname){   query <- sprintf("SELECT * FROM %s",Tabname)
  res <- dbGetQuery(con, query)
 
etc
HTH,Eric
On Fri, Jul 2, 2021 at 9:39 PM Kai Yang via R-help  wrote:

Hello List,

The previous post look massy. I repost my question. Sorry,


I need to generate summary report for many tables (>200 tables). For each 
table, I can use the script to generate report:
res <- dbGetQuery(con, "SELECT * FROM BIODBX.MECCUNIQUE2")
view(dfSummary(res), file = 
"W:/project/_Joe.B/MSSQL/try/summarytools.BIODBX.MECCUNIQUE2.html")
rm(res)
BIODBX.MECCUNIQUE2 is the name of table.

I have all of tables' name in a data frame. So, I'm trying to write a function 
to do this:
summ <- function(Tabname){
  res <- dbGetQuery(con, "SELECT * FROM Tabname")
  view(dfSummary(res), file = 
"W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")
  rm(res)
}
for (i in dbtable$Tot_table)
{
  Tabname <- as.character(sqldf(sprintf("SELECT Tot_table FROM dbtable", i)))
  summ(Tabname)
}

1. I created  a function summ, the argument is Tabname. I put the Tabname in 
the function. I hope it can be replaced one by one
2. the table dbtable contents all tables' name (>200 rows), the field name is 
Tot_table
3. I want use "for" to establish a loop, which can automatic generate a summary 
report for each table

but I got error message below:
 Error: nanodbc/nanodbc.cpp:1655: 42000: [Microsoft][ODBC Driver 17 for SQL 
Server][SQL Server]Invalid object name 'Tabname'.  
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be 
prepared. 

 'SELECT * FROM Tabname' 
10. stop(structure(list(message = "nanodbc/nanodbc.cpp:1655: 42000: 
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid 
object name 'Tabname'.  [Microsoft][ODBC Driver 17 for SQL Server][SQL 
Server]Statement(s) could not be prepared. \n 
'SELECT * FROM Tabname'", 
    call = NULL, cppstack = NULL), class = c("odbc::odbc_error", 
"C++Error", "error", "condition"))) 
9.new_result(connection@ptr, statement, immediate) 
8.OdbcResult(connection = conn, statement = statement, params = params,     
immediate = immediate) 
7..local(conn, statement, ...) 
6.dbSendQuery(conn, statement, params = params, ...) 
5.dbSendQuery(conn, statement, params = params, ...) 
4..local(conn, statement, ...) 
3.dbGetQuery(con, "SELECT * FROM Tabname") 
2.dbGetQuery(con, "SELECT * FROM Tabname") 
1.summ(Tabname) 

it seems the tables' name is not successfully pass into query. can someone give 
me an instruction for this?
many thanks,
Kai


        [[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] R Function question, (repost to fix the messy work format)

2021-07-02 Thread Eric Berger
Modify the summ() function to start like this

summ <- function(Tabname){
   query <- sprintf(" SELECT * FROM %s",Tabname)
  res <- dbGetQuery(con, query)

etc

HTH,
Eric

On Fri, Jul 2, 2021 at 9:39 PM Kai Yang via R-help 
wrote:

> Hello List,
>
> The previous post look massy. I repost my question. Sorry,
>
>
> I need to generate summary report for many tables (>200 tables). For each
> table, I can use the script to generate report:
> res <- dbGetQuery(con, "SELECT * FROM BIODBX.MECCUNIQUE2")
> view(dfSummary(res), file =
> "W:/project/_Joe.B/MSSQL/try/summarytools.BIODBX.MECCUNIQUE2.html")
> rm(res)
> BIODBX.MECCUNIQUE2 is the name of table.
>
> I have all of tables' name in a data frame. So, I'm trying to write a
> function to do this:
> summ <- function(Tabname){
>   res <- dbGetQuery(con, "SELECT * FROM Tabname")
>   view(dfSummary(res), file =
> "W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")
>   rm(res)
> }
> for (i in dbtable$Tot_table)
> {
>   Tabname <- as.character(sqldf(sprintf("SELECT Tot_table FROM dbtable",
> i)))
>   summ(Tabname)
> }
>
> 1. I created  a function summ, the argument is Tabname. I put the Tabname
> in the function. I hope it can be replaced one by one
> 2. the table dbtable contents all tables' name (>200 rows), the field name
> is Tot_table
> 3. I want use "for" to establish a loop, which can automatic generate a
> summary report for each table
>
> but I got error message below:
>  Error: nanodbc/nanodbc.cpp:1655: 42000: [Microsoft][ODBC Driver 17 for
> SQL Server][SQL Server]Invalid object name 'Tabname'.
> [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could
> not be prepared.
>
>  'SELECT * FROM Tabname'
> 10. stop(structure(list(message = "nanodbc/nanodbc.cpp:1655: 42000:
> [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid
> object name 'Tabname'.  [Microsoft][ODBC Driver 17 for SQL Server][SQL
> Server]Statement(s) could not be prepared. \n
> 'SELECT * FROM Tabname'",
> call = NULL, cppstack = NULL), class = c("odbc::odbc_error",
> "C++Error", "error", "condition")))
> 9.new_result(connection@ptr, statement, immediate)
> 8.OdbcResult(connection = conn, statement = statement, params = params,
>  immediate = immediate)
> 7..local(conn, statement, ...)
> 6.dbSendQuery(conn, statement, params = params, ...)
> 5.dbSendQuery(conn, statement, params = params, ...)
> 4..local(conn, statement, ...)
> 3.dbGetQuery(con, "SELECT * FROM Tabname")
> 2.dbGetQuery(con, "SELECT * FROM Tabname")
> 1.summ(Tabname)
>
> it seems the tables' name is not successfully pass into query. can someone
> give me an instruction for this?
> many thanks,
> Kai
>
>
> [[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] R Function question, (repost to fix the messy work format)

2021-07-02 Thread Kai Yang via R-help
Hello List,

The previous post look massy. I repost my question. Sorry,


I need to generate summary report for many tables (>200 tables). For each 
table, I can use the script to generate report:
res <- dbGetQuery(con, "SELECT * FROM BIODBX.MECCUNIQUE2")
view(dfSummary(res), file = 
"W:/project/_Joe.B/MSSQL/try/summarytools.BIODBX.MECCUNIQUE2.html")
rm(res)
BIODBX.MECCUNIQUE2 is the name of table.

I have all of tables' name in a data frame. So, I'm trying to write a function 
to do this:
summ <- function(Tabname){
  res <- dbGetQuery(con, "SELECT * FROM Tabname")
  view(dfSummary(res), file = 
"W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")
  rm(res)
}
for (i in dbtable$Tot_table)
{
  Tabname <- as.character(sqldf(sprintf("SELECT Tot_table FROM dbtable", i)))
  summ(Tabname)
}

1. I created  a function summ, the argument is Tabname. I put the Tabname in 
the function. I hope it can be replaced one by one
2. the table dbtable contents all tables' name (>200 rows), the field name is 
Tot_table
3. I want use "for" to establish a loop, which can automatic generate a summary 
report for each table

but I got error message below:
 Error: nanodbc/nanodbc.cpp:1655: 42000: [Microsoft][ODBC Driver 17 for SQL 
Server][SQL Server]Invalid object name 'Tabname'.  
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be 
prepared. 

 'SELECT * FROM Tabname' 
10. stop(structure(list(message = "nanodbc/nanodbc.cpp:1655: 42000: 
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid 
object name 'Tabname'.  [Microsoft][ODBC Driver 17 for SQL Server][SQL 
Server]Statement(s) could not be prepared. \n 
'SELECT * FROM Tabname'", 
    call = NULL, cppstack = NULL), class = c("odbc::odbc_error", 
"C++Error", "error", "condition"))) 
9.new_result(connection@ptr, statement, immediate) 
8.OdbcResult(connection = conn, statement = statement, params = params,     
immediate = immediate) 
7..local(conn, statement, ...) 
6.dbSendQuery(conn, statement, params = params, ...) 
5.dbSendQuery(conn, statement, params = params, ...) 
4..local(conn, statement, ...) 
3.dbGetQuery(con, "SELECT * FROM Tabname") 
2.dbGetQuery(con, "SELECT * FROM Tabname") 
1.summ(Tabname) 

it seems the tables' name is not successfully pass into query. can someone give 
me an instruction for this?
many thanks,
Kai


[[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] R function question

2021-07-02 Thread Kai Yang via R-help
Hello List,I need to generate summary report for many tables (>200 tables). For 
each table, I can use the script to generate repost:
res <- dbGetQuery(con, "SELECT * FROM BIODBX.MECCUNIQUE2")view(dfSummary(res), 
file = 
"W:/project/_Joe.B/MSSQL/try/summarytools.BIODBX.MECCUNIQUE2.html")rm(res)
BIODBX.MECCUNIQUE2 is the name of table.
I have all of tables' name in a data frame. So, I'm trying to write a function 
to do this:
summ <- function(Tabname){  res <- dbGetQuery(con, "SELECT * FROM Tabname")  
view(dfSummary(res), file = 
"W:/project/_Joe.B/MSSQL/try/summarytools.Tabname.html")  rm(res)}
for (i in dbtable$Tot_table){  Tabname <- as.character(sqldf(sprintf("SELECT 
Tot_table FROM dbtable", i)))  summ(Tabname)}
1. I created  a function summ, the argument is Tabname. I put the Tabname in 
the function. I hope it can be replaced one by one2. the table dbtable contents 
all tables' name (>200 rows), the field name is Tot_table3. I want use "for" to 
establish a loop, which can automatic generate a summary report for each table
but I got error message below: Error: nanodbc/nanodbc.cpp:1655: 42000: 
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 
'Tabname'.  [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) 
could not be prepared.  'SELECT * FROM Tabname' 10. 
stop(structure(list(message = "nanodbc/nanodbc.cpp:1655: 42000: 
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 
'Tabname'.  [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) 
could not be prepared. \n 'SELECT * FROM Tabname'",     call = NULL, 
cppstack = NULL), class = c("odbc::odbc_error", "C++Error", "error", 
"condition"))) 9.new_result(connection@ptr, statement, immediate) 
8.OdbcResult(connection = conn, statement = statement, params = params,     
immediate = immediate) 7..local(conn, statement, ...) 6.dbSendQuery(conn, 
statement, params = params, ...) 5.dbSendQuery(conn, statement, params = 
params, ...) 4..local(conn, statement, ...) 3.dbGetQuery(con, "SELECT * FROM 
Tabname") 2.dbGetQuery(con, "SELECT * FROM Tabname") 1.summ(Tabname) 
it seems the tables' name is not successfully pass into query. can someone give 
me an instruction for this?
many thanks,Kai

[[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 of "matrix"

2020-10-22 Thread Bill Dunlap
>  10.1/0.1 was successfully calculated

  Note that 'computed as' is not the same as 'printed as'.   Computations
are
done with 52 binary digits of precision and printing is, by default, done
with
7 decimal digits of precision.  See FAQ 7.31.

> 101 - 10.1/0.1
[1] 1.421085e-14
> options(digits=17)
> 10.1/0.1
[1] 100.99
> trunc(10.1/0.1)
[1] 100

On Thu, Oct 22, 2020 at 11:42 AM 奈良県奈良市  wrote:

> Dear R project team
>
> I used the function of "matrix" as follows:
> matrix(c(1:3030), 10.1/0.1)
> However, in the function, matrix, 10.1/0.1 was regarded as 100 not as 101.
> Therefore, a warning message appeared.
> On the other hand, matrix(c(1:3030), 101) or matrix(c(1:3030), 10.1*10) was
> OK. Of course, simply, 10.1/0.1 was successfully calculated. However,
> In the "matrix" environment, 10.1/0.1 was calculated as 100.
>
> Would you give me some answers?
>
> Sincerely
>
> Kazuki Sakura
>
> [[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] Function of "matrix"

2020-10-22 Thread Patrick (Malone Quantitative)
(Neglected to cc the list--please reply-all to this version)

What was the warning?

I hazard a guess you've run into precision issues for binary
representation, and the result of your division is not *exactly* 101.

Pat

On Thu, Oct 22, 2020 at 2:42 PM 奈良県奈良市  wrote:
>
> Dear R project team
>
> I used the function of "matrix" as follows:
> matrix(c(1:3030), 10.1/0.1)
> However, in the function, matrix, 10.1/0.1 was regarded as 100 not as 101.
> Therefore, a warning message appeared.
> On the other hand, matrix(c(1:3030), 101) or matrix(c(1:3030), 10.1*10) was
> OK. Of course, simply, 10.1/0.1 was successfully calculated. However,
> In the "matrix" environment, 10.1/0.1 was calculated as 100.
>
> Would you give me some answers?
>
> Sincerely
>
> Kazuki Sakura
>
> [[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.



-- 
Patrick S. Malone, Ph.D., Malone Quantitative
NEW Service Models: http://malonequantitative.com

He/Him/His

__
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 of "matrix"

2020-10-22 Thread Bert Gunter
1. Answers on this list are from volunteers who are not part of any R
project team. We have no official status and what we say comes with no
guarantees.

2. There is no such thing as a "matrix 'environment' ".

3. The answer to your question is "computer arithmetic." See FAQ 7.31.
Someone may follow up with a more specific answer for your particular
calculation, however.

Cheers,

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Oct 22, 2020 at 11:41 AM 奈良県奈良市  wrote:

> Dear R project team
>
> I used the function of "matrix" as follows:
> matrix(c(1:3030), 10.1/0.1)
> However, in the function, matrix, 10.1/0.1 was regarded as 100 not as 101.
> Therefore, a warning message appeared.
> On the other hand, matrix(c(1:3030), 101) or matrix(c(1:3030), 10.1*10) was
> OK. Of course, simply, 10.1/0.1 was successfully calculated. However,
> In the "matrix" environment, 10.1/0.1 was calculated as 100.
>
> Would you give me some answers?
>
> Sincerely
>
> Kazuki Sakura
>
> [[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] Function of "matrix"

2020-10-22 Thread 奈良県奈良市
Dear R project team

I used the function of "matrix" as follows:
matrix(c(1:3030), 10.1/0.1)
However, in the function, matrix, 10.1/0.1 was regarded as 100 not as 101.
Therefore, a warning message appeared.
On the other hand, matrix(c(1:3030), 101) or matrix(c(1:3030), 10.1*10) was
OK. Of course, simply, 10.1/0.1 was successfully calculated. However,
In the "matrix" environment, 10.1/0.1 was calculated as 100.

Would you give me some answers?

Sincerely

Kazuki Sakura

[[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 that finds elements from matrix, and saves the indices of the elements to another matrix

2020-09-14 Thread Rui Barradas

Hello,

This is simple:


which(A == 1, arr.ind = TRUE)


Hope this helps,

Rui Barradas

Às 12:03 de 14/09/20, Tuomas Koponen escreveu:

Hi all dear R-list users,

This might sound a silly problem, but but for one reason or another it has
proved unsolvable to me.

I need to solve the following task. I have tried to use two nested for
loops as a solution, but have not been able to made it work. It would be
great, if someone could formulate a code for me:

I need to create a function X that takes as its input a 10x10 matrix, which
elements consists of ones and zeros. The function X must find the elements
in the matrix A that are "ones", and save the indices of those elements in
2-column matrix, in a following way: the first column has a row number, and
the second a column number.

The answer should be formulated in a way, that it uses two nested for
loops. The matrix to be returned has a maximum of 100 rows, so one
possibility exists for a 100x2 matrix filled with zeros in the index and
finally separate those rows with zeros.

I have tried the following code:

A<-matrix(1:0, nrow = 10, ncol = 10)

X <- data.frame()
for (i in seq(1, nrow(A))) {
for (j in seq(1,ncol(A))) {
if (A [i,j] > 0) {

new_row <- data.frame(Row_number= rownames(A)[i], Column_number=
colnames(A)[j])

X <- rbind(X, new_row)

   }

   }
}

I only manage to get "Error: object 'X' not found", as a result.

thanks in advance for your help.

Br. Tuomas

[[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] Function that finds elements from matrix, and saves the indices of the elements to another matrix

2020-09-14 Thread Bert Gunter
Is this a homework problem? We try not to do others' homework here.

Incidentally, this can easily be done much more efficiently without any
for() loops.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Sep 14, 2020 at 11:50 AM Tuomas Koponen 
wrote:

> Hi all dear R-list users,
>
> This might sound a silly problem, but but for one reason or another it has
> proved unsolvable to me.
>
> I need to solve the following task. I have tried to use two nested for
> loops as a solution, but have not been able to made it work. It would be
> great, if someone could formulate a code for me:
>
> I need to create a function X that takes as its input a 10x10 matrix, which
> elements consists of ones and zeros. The function X must find the elements
> in the matrix A that are "ones", and save the indices of those elements in
> 2-column matrix, in a following way: the first column has a row number, and
> the second a column number.
>
> The answer should be formulated in a way, that it uses two nested for
> loops. The matrix to be returned has a maximum of 100 rows, so one
> possibility exists for a 100x2 matrix filled with zeros in the index and
> finally separate those rows with zeros.
>
> I have tried the following code:
>
> A<-matrix(1:0, nrow = 10, ncol = 10)
>
> X <- data.frame()
> for (i in seq(1, nrow(A))) {
> for (j in seq(1,ncol(A))) {
> if (A [i,j] > 0) {
>
> new_row <- data.frame(Row_number= rownames(A)[i], Column_number=
> colnames(A)[j])
>
> X <- rbind(X, new_row)
>
>   }
>
>   }
> }
>
> I only manage to get "Error: object 'X' not found", as a result.
>
> thanks in advance for your help.
>
> Br. Tuomas
>
> [[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] Function that finds elements from matrix, and saves the indices of the elements to another matrix

2020-09-14 Thread Tuomas Koponen
Hi all dear R-list users,

This might sound a silly problem, but but for one reason or another it has
proved unsolvable to me.

I need to solve the following task. I have tried to use two nested for
loops as a solution, but have not been able to made it work. It would be
great, if someone could formulate a code for me:

I need to create a function X that takes as its input a 10x10 matrix, which
elements consists of ones and zeros. The function X must find the elements
in the matrix A that are "ones", and save the indices of those elements in
2-column matrix, in a following way: the first column has a row number, and
the second a column number.

The answer should be formulated in a way, that it uses two nested for
loops. The matrix to be returned has a maximum of 100 rows, so one
possibility exists for a 100x2 matrix filled with zeros in the index and
finally separate those rows with zeros.

I have tried the following code:

A<-matrix(1:0, nrow = 10, ncol = 10)

X <- data.frame()
for (i in seq(1, nrow(A))) {
for (j in seq(1,ncol(A))) {
if (A [i,j] > 0) {

new_row <- data.frame(Row_number= rownames(A)[i], Column_number=
colnames(A)[j])

X <- rbind(X, new_row)

  }

  }
}

I only manage to get "Error: object 'X' not found", as a result.

thanks in advance for your help.

Br. Tuomas

[[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 to return plots

2020-06-12 Thread Naresh Gurbuxani
Thanks for your quick response.  It works as I wanted. 



From: Rui Barradas 
Sent: Friday, June 12, 2020 7:08 AM
To: Naresh Gurbuxani ; r-help@r-project.org 

Subject: Re: [R] function to return plots 
 
Hello,

plot.list is a list, try '[[' to access its members.
('[' returns sub-lists.)


plot(plot.list[[1]], position = c(0, 0, 1, 0.5), more = TRUE) #Works
plot(plot.list[[2]], position = c(0, 0.5, 1, 1), more = FALSE) #Works


Hope this helps,

Rui Barradas

Às 10:52 de 12/06/20, Naresh Gurbuxani escreveu:
> 
> I want to write a function that will return lattice plots.  This simple
> function output a list of two plots.  These plots can be
> individually shown on the console.  But I am unable to put them on two
> panels of a single plot.
> 
> What changes do I need to make to this function?
> 
> Thanks,
> Naresh
> 
> library(lattice)
> 
> getPlots <- function(){
>  x <- rnorm(1000)
>  plt1 <- histogram(x)
>  plt2 <- bwplot(x)
>  list(plt1, plt2)
> }
> 
> plot.list <- getPlots()
> 
> plot.list[1] #Plots graph
> plot.list[2] #Plots graph
> 
> plot(plot.list[1], position = c(0, 0, 1, 0.5), more = TRUE) #Error message
> plot(plot.list[2], position = c(0, 0.5, 1, 1), more = FALSE) #Error message
> 
> ## Plotting outside function works
> x <- rnorm(1000)
> plt1 <- histogram(x)
> plt2 <- bwplot(x)
> plot(plt1, position = c(0, 0, 1, 0.5), more = TRUE)
> plot(plt2, position = c(0, 0.5, 1, 1), more = FALSE)
> 
> __
> 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] function to return plots

2020-06-12 Thread Rui Barradas

Hello,

plot.list is a list, try '[[' to access its members.
('[' returns sub-lists.)


plot(plot.list[[1]], position = c(0, 0, 1, 0.5), more = TRUE) #Works
plot(plot.list[[2]], position = c(0, 0.5, 1, 1), more = FALSE) #Works


Hope this helps,

Rui Barradas

Às 10:52 de 12/06/20, Naresh Gurbuxani escreveu:


I want to write a function that will return lattice plots.  This simple
function output a list of two plots.  These plots can be
individually shown on the console.  But I am unable to put them on two
panels of a single plot.

What changes do I need to make to this function?

Thanks,
Naresh

library(lattice)

getPlots <- function(){
 x <- rnorm(1000)
 plt1 <- histogram(x)
 plt2 <- bwplot(x)
 list(plt1, plt2)
}

plot.list <- getPlots()

plot.list[1] #Plots graph
plot.list[2] #Plots graph

plot(plot.list[1], position = c(0, 0, 1, 0.5), more = TRUE) #Error message
plot(plot.list[2], position = c(0, 0.5, 1, 1), more = FALSE) #Error message

## Plotting outside function works
x <- rnorm(1000)
plt1 <- histogram(x)
plt2 <- bwplot(x)
plot(plt1, position = c(0, 0, 1, 0.5), more = TRUE)
plot(plt2, position = c(0, 0.5, 1, 1), more = FALSE)

__
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] function to return plots

2020-06-12 Thread Jim Lemon
Hi Naresh,
The somewhat obscure syntax of lattice.

print(plot.list[[1]])
print(plot.list[[2]])

Jim

On Fri, Jun 12, 2020 at 7:53 PM Naresh Gurbuxani
 wrote:
>
>
> I want to write a function that will return lattice plots.  This simple
> function output a list of two plots.  These plots can be
> individually shown on the console.  But I am unable to put them on two
> panels of a single plot.
>
> What changes do I need to make to this function?
>
> Thanks,
> Naresh
>
> library(lattice)
>
> getPlots <- function(){
> x <- rnorm(1000)
> plt1 <- histogram(x)
> plt2 <- bwplot(x)
> list(plt1, plt2)
> }
>
> plot.list <- getPlots()
>
> plot.list[1] #Plots graph
> plot.list[2] #Plots graph
>
> plot(plot.list[1], position = c(0, 0, 1, 0.5), more = TRUE) #Error message
> plot(plot.list[2], position = c(0, 0.5, 1, 1), more = FALSE) #Error message
>
> ## Plotting outside function works
> x <- rnorm(1000)
> plt1 <- histogram(x)
> plt2 <- bwplot(x)
> plot(plt1, position = c(0, 0, 1, 0.5), more = TRUE)
> plot(plt2, position = c(0, 0.5, 1, 1), more = FALSE)
>
> __
> 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] function to return plots

2020-06-12 Thread Naresh Gurbuxani


I want to write a function that will return lattice plots.  This simple
function output a list of two plots.  These plots can be
individually shown on the console.  But I am unable to put them on two
panels of a single plot.

What changes do I need to make to this function?

Thanks,
Naresh

library(lattice)

getPlots <- function(){
x <- rnorm(1000)
plt1 <- histogram(x)
plt2 <- bwplot(x)
list(plt1, plt2)
}

plot.list <- getPlots()

plot.list[1] #Plots graph
plot.list[2] #Plots graph

plot(plot.list[1], position = c(0, 0, 1, 0.5), more = TRUE) #Error message
plot(plot.list[2], position = c(0, 0.5, 1, 1), more = FALSE) #Error message

## Plotting outside function works
x <- rnorm(1000)
plt1 <- histogram(x)
plt2 <- bwplot(x)
plot(plt1, position = c(0, 0, 1, 0.5), more = TRUE)
plot(plt2, position = c(0, 0.5, 1, 1), more = FALSE)

__
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 Hints in Mac Dark Mode

2020-05-08 Thread Marc Schwartz via R-help



> On May 8, 2020, at 11:02 AM, Jeff Newmiller  wrote:
> 
> You seem to be confusing R and RStudio... so yeah, wrong mailing list. I 
> don't know exactly where you should post either. Perhaps the GitHub issues 
> page for RStudio?
> 
> On May 6, 2020 12:54:43 PM PDT, Andrew Swift via R-help 
>  wrote:
>> Sorry, wasn’t sure exactly where to post this but I noticed that with R
>> 4.0.0 when running a Mac in Dark Mode that the Function Hints at the
>> bottom of the Console and Editor windows become invisible.  
>> Thanks. 


Hi,

Actually, I am not sure that is the case. 

See the attached screen capture of the default R.app (which I do not use) when 
the desktop is set to dark mode, which I also do not use.

When in light mode, those hints in the lower left hand corner are black, and 
they switch to white in dark mode, making them almost impossible to see.

For Andrew, if this is correct, and you are not referring to RStudio per Jeff, 
you should post this to r-sig-mac:
  
  https://stat.ethz.ch/mailman/listinfo/r-sig-mac

Otherwise, if it is RStudio, they have their own support here:

   https://support.rstudio.com/hc/en-us

Regards,

Marc Schwartz




__
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 Hints in Mac Dark Mode

2020-05-08 Thread Andrew Swift via R-help
Marc,

Yes, that is exactly the issue.  I’ll post to r-sig-mac.

On May 8, 2020, at 10:11 AM, Marc Schwartz 
mailto:marc_schwa...@me.com>> wrote:



On May 8, 2020, at 11:02 AM, Jeff Newmiller 
mailto:jdnew...@dcn.davis.ca.us>> wrote:

You seem to be confusing R and RStudio... so yeah, wrong mailing list. I don't 
know exactly where you should post either. Perhaps the GitHub issues page for 
RStudio?

On May 6, 2020 12:54:43 PM PDT, Andrew Swift via R-help 
mailto:r-help@r-project.org>> wrote:
Sorry, wasn’t sure exactly where to post this but I noticed that with R
4.0.0 when running a Mac in Dark Mode that the Function Hints at the
bottom of the Console and Editor windows become invisible.
Thanks.


Hi,

Actually, I am not sure that is the case.

See the attached screen capture of the default R.app (which I do not use) when 
the desktop is set to dark mode, which I also do not use.

When in light mode, those hints in the lower left hand corner are black, and 
they switch to white in dark mode, making them almost impossible to see.

For Andrew, if this is correct, and you are not referring to RStudio per Jeff, 
you should post this to r-sig-mac:

  
https://stat.ethz.ch/mailman/listinfo/r-sig-mac

Otherwise, if it is RStudio, they have their own support here:

   
https://support.rstudio.com/hc/en-us

Regards,

Marc Schwartz






[[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 Hints in Mac Dark Mode

2020-05-08 Thread Jeff Newmiller
You seem to be confusing R and RStudio... so yeah, wrong mailing list. I don't 
know exactly where you should post either. Perhaps the GitHub issues page for 
RStudio?

On May 6, 2020 12:54:43 PM PDT, Andrew Swift via R-help  
wrote:
>Sorry, wasn’t sure exactly where to post this but I noticed that with R
>4.0.0 when running a Mac in Dark Mode that the Function Hints at the
>bottom of the Console and Editor windows become invisible.  
>Thanks. 
>__
>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.


[R] Function Hints in Mac Dark Mode

2020-05-08 Thread Andrew Swift via R-help
Sorry, wasn’t sure exactly where to post this but I noticed that with R 4.0.0 
when running a Mac in Dark Mode that the Function Hints at the bottom of the 
Console and Editor windows become invisible.  
Thanks. 
__
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 sample: diferences across R versions

2019-07-31 Thread Jose Claudio Faria
It works!
Thanks,
///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
Jose Claudio Faria
UESC/DCET/Brasil
joseclaudio.faria at gmail.com
Telefones:
55(73)3680.5545 - UESC
55(73)99966.9100 - VIVO
///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\

If you have software to deal with statistics, you have arms;
if you have good software, you have arms and legs;
if you have software like R, you have arms, legs and wings...
the height of your flight depends only on you!

Em ter, 30 de jul de 2019 às 22:00, Jeff Newmiller
 escreveu:
>
> There seem to be a couple of ways to do this.
>
> Rngkind( sample.kind="Rounding" )
>
> or
>
> RNGversion("3.5.2")
>
> per
>
> ?Random
>
> https://stat.ethz.ch/pipermail/r-help/2019-June/463109.html
>
> On July 30, 2019 5:31:13 PM PDT, Jose Claudio Faria 
>  wrote:
> >Thanks Patrick.
> >
> >I took a look at the documentation of the RNGkind and RNGversion
> >functions but didn't understand how they work. Can you exemplify how I
> >can, through them, to recapture the old behavior?
> >
> >Best,
> >///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
> >Jose Claudio Faria
> >UESC/DCET/Brasil
> >joseclaudio.faria at gmail.com
> >Telefones:
> >55(73)3680.5545 - UESC
> >55(73)99966.9100 - VIVO
> >///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
> >
> >If you have software to deal with statistics, you have arms;
> >if you have good software, you have arms and legs;
> >if you have software like R, you have arms, legs and wings...
> >the height of your flight depends only on you!
> >
> >Em ter, 30 de jul de 2019 às 19:56, Patrick (Malone Quantitative)
> > escreveu:
> >>
> >> Poorly phrased--makes it act differently with respect to set.seed() .
> >>
> >> On Tue, Jul 30, 2019 at 6:55 PM Patrick (Malone Quantitative)
> >>  wrote:
> >> >
> >> > My understanding is that sample() in 3.6.0 did, in fact, change in
> >> > ways that detach it from set.seed().
> >> >
> >> > You can use RNGkind() or RNGversion() to recapture the old
> >behavior.
> >> >
> >> > See https://cran.rstudio.com/bin/windows/base/NEWS.R-3.6.1.html in
> >the
> >> > section CHANGES IN R 3.6.0 .
> >> >
> >> > Also, please do not post in HTML.
> >> >
> >> > Pat
> >> >
> >> > On Tue, Jul 30, 2019 at 6:45 PM Jose Claudio Faria
> >> >  wrote:
> >> > >
> >> > > Hi,
> >> > > I just noticed the difference in a teaching data generation
> >script between
> >> > > version 3.6.1 and earlier.
> >> > >
> >> > > #! R version 3.4.3
> >> > > set.seed(2019); sample(1:10, 1)
> >> > > [1] 8
> >> > >
> >> > > #! R version 3.5.1patched
> >> > > set.seed(2019); sample(1:10, 1)
> >> > > [1] 8
> >> > >
> >> > > #! R version 3.5.3patched
> >> > > set.seed(2019); sample(1:10, 1)
> >> > > [1] 8
> >> > >
> >> > > #! R version 3.6.0patched
> >> > > set.seed(2019); sample(1:10, 1)
> >> > > [1] 8
> >> > >
> >> > > #! R version 3.6.1patched
> >> > > set.seed(2019); sample(1:10, 1)
> >> > > [1] 9  # <- Here!
> >> > >
> >> > > Is it a bug?
> >> > > if not (is a new feature) how can I maintain compatibility
> >between version
> >> > > 3.6.1 and all others?
> >> > >
> >> > > Regards,
> >> > > ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
> >> > > Jose Claudio Faria
> >> > > UESC/DCET/Brasil
> >> > > joseclaudio.faria at gmail.com
> >> > > Telefones:
> >> > > 55(73)3680.5545 - UESC
> >> > > 55(73)99966.9100 - VIVO
> >> > > ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
> >> > >
> >> > > If you have software to deal with statistics, you have arms;
> >> > > if you have good software, you have arms and legs;
> >> > > if you have software like R, you have arms, legs and wings...
> >> > > the height of your flight depends only on you!
> >> > >
> >> > > [[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.
>
> --
> 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] function sample: diferences across R versions

2019-07-30 Thread Jeff Newmiller
There seem to be a couple of ways to do this.

Rngkind( sample.kind="Rounding" )

or

RNGversion("3.5.2")

per

?Random

https://stat.ethz.ch/pipermail/r-help/2019-June/463109.html

On July 30, 2019 5:31:13 PM PDT, Jose Claudio Faria 
 wrote:
>Thanks Patrick.
>
>I took a look at the documentation of the RNGkind and RNGversion
>functions but didn't understand how they work. Can you exemplify how I
>can, through them, to recapture the old behavior?
>
>Best,
>///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
>Jose Claudio Faria
>UESC/DCET/Brasil
>joseclaudio.faria at gmail.com
>Telefones:
>55(73)3680.5545 - UESC
>55(73)99966.9100 - VIVO
>///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
>
>If you have software to deal with statistics, you have arms;
>if you have good software, you have arms and legs;
>if you have software like R, you have arms, legs and wings...
>the height of your flight depends only on you!
>
>Em ter, 30 de jul de 2019 às 19:56, Patrick (Malone Quantitative)
> escreveu:
>>
>> Poorly phrased--makes it act differently with respect to set.seed() .
>>
>> On Tue, Jul 30, 2019 at 6:55 PM Patrick (Malone Quantitative)
>>  wrote:
>> >
>> > My understanding is that sample() in 3.6.0 did, in fact, change in
>> > ways that detach it from set.seed().
>> >
>> > You can use RNGkind() or RNGversion() to recapture the old
>behavior.
>> >
>> > See https://cran.rstudio.com/bin/windows/base/NEWS.R-3.6.1.html in
>the
>> > section CHANGES IN R 3.6.0 .
>> >
>> > Also, please do not post in HTML.
>> >
>> > Pat
>> >
>> > On Tue, Jul 30, 2019 at 6:45 PM Jose Claudio Faria
>> >  wrote:
>> > >
>> > > Hi,
>> > > I just noticed the difference in a teaching data generation
>script between
>> > > version 3.6.1 and earlier.
>> > >
>> > > #! R version 3.4.3
>> > > set.seed(2019); sample(1:10, 1)
>> > > [1] 8
>> > >
>> > > #! R version 3.5.1patched
>> > > set.seed(2019); sample(1:10, 1)
>> > > [1] 8
>> > >
>> > > #! R version 3.5.3patched
>> > > set.seed(2019); sample(1:10, 1)
>> > > [1] 8
>> > >
>> > > #! R version 3.6.0patched
>> > > set.seed(2019); sample(1:10, 1)
>> > > [1] 8
>> > >
>> > > #! R version 3.6.1patched
>> > > set.seed(2019); sample(1:10, 1)
>> > > [1] 9  # <- Here!
>> > >
>> > > Is it a bug?
>> > > if not (is a new feature) how can I maintain compatibility
>between version
>> > > 3.6.1 and all others?
>> > >
>> > > Regards,
>> > > ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
>> > > Jose Claudio Faria
>> > > UESC/DCET/Brasil
>> > > joseclaudio.faria at gmail.com
>> > > Telefones:
>> > > 55(73)3680.5545 - UESC
>> > > 55(73)99966.9100 - VIVO
>> > > ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
>> > >
>> > > If you have software to deal with statistics, you have arms;
>> > > if you have good software, you have arms and legs;
>> > > if you have software like R, you have arms, legs and wings...
>> > > the height of your flight depends only on you!
>> > >
>> > > [[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.

-- 
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] function sample: diferences across R versions

2019-07-30 Thread Jose Claudio Faria
Thanks Patrick.

I took a look at the documentation of the RNGkind and RNGversion
functions but didn't understand how they work. Can you exemplify how I
can, through them, to recapture the old behavior?

Best,
///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
Jose Claudio Faria
UESC/DCET/Brasil
joseclaudio.faria at gmail.com
Telefones:
55(73)3680.5545 - UESC
55(73)99966.9100 - VIVO
///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\

If you have software to deal with statistics, you have arms;
if you have good software, you have arms and legs;
if you have software like R, you have arms, legs and wings...
the height of your flight depends only on you!

Em ter, 30 de jul de 2019 às 19:56, Patrick (Malone Quantitative)
 escreveu:
>
> Poorly phrased--makes it act differently with respect to set.seed() .
>
> On Tue, Jul 30, 2019 at 6:55 PM Patrick (Malone Quantitative)
>  wrote:
> >
> > My understanding is that sample() in 3.6.0 did, in fact, change in
> > ways that detach it from set.seed().
> >
> > You can use RNGkind() or RNGversion() to recapture the old behavior.
> >
> > See https://cran.rstudio.com/bin/windows/base/NEWS.R-3.6.1.html in the
> > section CHANGES IN R 3.6.0 .
> >
> > Also, please do not post in HTML.
> >
> > Pat
> >
> > On Tue, Jul 30, 2019 at 6:45 PM Jose Claudio Faria
> >  wrote:
> > >
> > > Hi,
> > > I just noticed the difference in a teaching data generation script between
> > > version 3.6.1 and earlier.
> > >
> > > #! R version 3.4.3
> > > set.seed(2019); sample(1:10, 1)
> > > [1] 8
> > >
> > > #! R version 3.5.1patched
> > > set.seed(2019); sample(1:10, 1)
> > > [1] 8
> > >
> > > #! R version 3.5.3patched
> > > set.seed(2019); sample(1:10, 1)
> > > [1] 8
> > >
> > > #! R version 3.6.0patched
> > > set.seed(2019); sample(1:10, 1)
> > > [1] 8
> > >
> > > #! R version 3.6.1patched
> > > set.seed(2019); sample(1:10, 1)
> > > [1] 9  # <- Here!
> > >
> > > Is it a bug?
> > > if not (is a new feature) how can I maintain compatibility between version
> > > 3.6.1 and all others?
> > >
> > > Regards,
> > > ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
> > > Jose Claudio Faria
> > > UESC/DCET/Brasil
> > > joseclaudio.faria at gmail.com
> > > Telefones:
> > > 55(73)3680.5545 - UESC
> > > 55(73)99966.9100 - VIVO
> > > ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
> > >
> > > If you have software to deal with statistics, you have arms;
> > > if you have good software, you have arms and legs;
> > > if you have software like R, you have arms, legs and wings...
> > > the height of your flight depends only on you!
> > >
> > > [[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] function sample: diferences across R versions

2019-07-30 Thread Patrick (Malone Quantitative)
Poorly phrased--makes it act differently with respect to set.seed() .

On Tue, Jul 30, 2019 at 6:55 PM Patrick (Malone Quantitative)
 wrote:
>
> My understanding is that sample() in 3.6.0 did, in fact, change in
> ways that detach it from set.seed().
>
> You can use RNGkind() or RNGversion() to recapture the old behavior.
>
> See https://cran.rstudio.com/bin/windows/base/NEWS.R-3.6.1.html in the
> section CHANGES IN R 3.6.0 .
>
> Also, please do not post in HTML.
>
> Pat
>
> On Tue, Jul 30, 2019 at 6:45 PM Jose Claudio Faria
>  wrote:
> >
> > Hi,
> > I just noticed the difference in a teaching data generation script between
> > version 3.6.1 and earlier.
> >
> > #! R version 3.4.3
> > set.seed(2019); sample(1:10, 1)
> > [1] 8
> >
> > #! R version 3.5.1patched
> > set.seed(2019); sample(1:10, 1)
> > [1] 8
> >
> > #! R version 3.5.3patched
> > set.seed(2019); sample(1:10, 1)
> > [1] 8
> >
> > #! R version 3.6.0patched
> > set.seed(2019); sample(1:10, 1)
> > [1] 8
> >
> > #! R version 3.6.1patched
> > set.seed(2019); sample(1:10, 1)
> > [1] 9  # <- Here!
> >
> > Is it a bug?
> > if not (is a new feature) how can I maintain compatibility between version
> > 3.6.1 and all others?
> >
> > Regards,
> > ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
> > Jose Claudio Faria
> > UESC/DCET/Brasil
> > joseclaudio.faria at gmail.com
> > Telefones:
> > 55(73)3680.5545 - UESC
> > 55(73)99966.9100 - VIVO
> > ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
> >
> > If you have software to deal with statistics, you have arms;
> > if you have good software, you have arms and legs;
> > if you have software like R, you have arms, legs and wings...
> > the height of your flight depends only on you!
> >
> > [[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] function sample: diferences across R versions

2019-07-30 Thread Patrick (Malone Quantitative)
My understanding is that sample() in 3.6.0 did, in fact, change in
ways that detach it from set.seed().

You can use RNGkind() or RNGversion() to recapture the old behavior.

See https://cran.rstudio.com/bin/windows/base/NEWS.R-3.6.1.html in the
section CHANGES IN R 3.6.0 .

Also, please do not post in HTML.

Pat

On Tue, Jul 30, 2019 at 6:45 PM Jose Claudio Faria
 wrote:
>
> Hi,
> I just noticed the difference in a teaching data generation script between
> version 3.6.1 and earlier.
>
> #! R version 3.4.3
> set.seed(2019); sample(1:10, 1)
> [1] 8
>
> #! R version 3.5.1patched
> set.seed(2019); sample(1:10, 1)
> [1] 8
>
> #! R version 3.5.3patched
> set.seed(2019); sample(1:10, 1)
> [1] 8
>
> #! R version 3.6.0patched
> set.seed(2019); sample(1:10, 1)
> [1] 8
>
> #! R version 3.6.1patched
> set.seed(2019); sample(1:10, 1)
> [1] 9  # <- Here!
>
> Is it a bug?
> if not (is a new feature) how can I maintain compatibility between version
> 3.6.1 and all others?
>
> Regards,
> ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
> Jose Claudio Faria
> UESC/DCET/Brasil
> joseclaudio.faria at gmail.com
> Telefones:
> 55(73)3680.5545 - UESC
> 55(73)99966.9100 - VIVO
> ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
>
> If you have software to deal with statistics, you have arms;
> if you have good software, you have arms and legs;
> if you have software like R, you have arms, legs and wings...
> the height of your flight depends only on you!
>
> [[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] function sample: diferences across R versions

2019-07-30 Thread Jose Claudio Faria
Hi,
I just noticed the difference in a teaching data generation script between
version 3.6.1 and earlier.

#! R version 3.4.3
set.seed(2019); sample(1:10, 1)
[1] 8

#! R version 3.5.1patched
set.seed(2019); sample(1:10, 1)
[1] 8

#! R version 3.5.3patched
set.seed(2019); sample(1:10, 1)
[1] 8

#! R version 3.6.0patched
set.seed(2019); sample(1:10, 1)
[1] 8

#! R version 3.6.1patched
set.seed(2019); sample(1:10, 1)
[1] 9  # <- Here!

Is it a bug?
if not (is a new feature) how can I maintain compatibility between version
3.6.1 and all others?

Regards,
///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
Jose Claudio Faria
UESC/DCET/Brasil
joseclaudio.faria at gmail.com
Telefones:
55(73)3680.5545 - UESC
55(73)99966.9100 - VIVO
///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\

If you have software to deal with statistics, you have arms;
if you have good software, you have arms and legs;
if you have software like R, you have arms, legs and wings...
the height of your flight depends only on you!

[[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] Only change one parameter(n times) in R function then get outputs (n times)

2019-06-10 Thread Thevaraja, Mayooran
Thanks for your help  Jeff. I will try it



Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10



From: Jeff Newmiller<mailto:jdnew...@dcn.davis.ca.us>
Sent: Monday, June 10, 2019 08:20 PM
To: r-help@r-project.org<mailto:r-help@r-project.org>; Bert 
Gunter<mailto:bgunter.4...@gmail.com>; Thevaraja, 
Mayooran<mailto:m.thevar...@massey.ac.nz>
Cc: r-help@r-project.org<mailto:r-help@r-project.org>
Subject: Re: [R] Only change one parameter(n times) in R function then get 
outputs (n times)



Sorry ... that should have been "sapply"...

On June 9, 2019 9:31:32 PM PDT, Jeff Newmiller  wrote:
>supply might be useful. Or you may get some ideas from [1].
>
>[1] https://jdnewmil.github.io/RLoopsAndGroups/DoItAgainR.html
>
>On June 9, 2019 6:07:34 PM PDT, Bert Gunter 
>wrote:
>>Yes. Spend some time with some R tutorials to learn the basics of R
>>programming.
>>
>>Bert Gunter
>>
>>"The trouble with having an open mind is that people keep coming along
>>and
>>sticking things into it."
>>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>>On Sun, Jun 9, 2019 at 3:14 PM Thevaraja, Mayooran
>>
>>wrote:
>>
>>> Hello Friends,
>>>   I have my own written an R function comparison
>>> (p,d,N). I need to get output corresponding changes in p while d and
>>N are
>>> fixed. Also, my output is given three values such as A, B and C.
>>Suppose if
>>> I change ten different p's values, we will get ten values of A, B
>and
>>C. My
>>> goal is I want to draw the curve A vs B, C. Anyone have any ideas? I
>>am
>>> trying mapply function.
>>>
>>>
>>> Regards
>>> Mayooran
>>>
>>> [[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.

--
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] Only change one parameter(n times) in R function then get outputs (n times)

2019-06-10 Thread Jeff Newmiller
Sorry ... that should have been "sapply"...

On June 9, 2019 9:31:32 PM PDT, Jeff Newmiller  wrote:
>supply might be useful. Or you may get some ideas from [1].
>
>[1] https://jdnewmil.github.io/RLoopsAndGroups/DoItAgainR.html
>
>On June 9, 2019 6:07:34 PM PDT, Bert Gunter 
>wrote:
>>Yes. Spend some time with some R tutorials to learn the basics of R
>>programming.
>>
>>Bert Gunter
>>
>>"The trouble with having an open mind is that people keep coming along
>>and
>>sticking things into it."
>>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>>On Sun, Jun 9, 2019 at 3:14 PM Thevaraja, Mayooran
>>
>>wrote:
>>
>>> Hello Friends,
>>>   I have my own written an R function comparison
>>> (p,d,N). I need to get output corresponding changes in p while d and
>>N are
>>> fixed. Also, my output is given three values such as A, B and C.
>>Suppose if
>>> I change ten different p's values, we will get ten values of A, B
>and
>>C. My
>>> goal is I want to draw the curve A vs B, C. Anyone have any ideas? I
>>am
>>> trying mapply function.
>>>
>>>
>>> Regards
>>> Mayooran
>>>
>>> [[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.

-- 
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] Only change one parameter(n times) in R function then get outputs (n times)

2019-06-09 Thread Jeff Newmiller
supply might be useful. Or you may get some ideas from [1].

[1] https://jdnewmil.github.io/RLoopsAndGroups/DoItAgainR.html

On June 9, 2019 6:07:34 PM PDT, Bert Gunter  wrote:
>Yes. Spend some time with some R tutorials to learn the basics of R
>programming.
>
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and
>sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>On Sun, Jun 9, 2019 at 3:14 PM Thevaraja, Mayooran
>
>wrote:
>
>> Hello Friends,
>>   I have my own written an R function comparison
>> (p,d,N). I need to get output corresponding changes in p while d and
>N are
>> fixed. Also, my output is given three values such as A, B and C.
>Suppose if
>> I change ten different p's values, we will get ten values of A, B and
>C. My
>> goal is I want to draw the curve A vs B, C. Anyone have any ideas? I
>am
>> trying mapply function.
>>
>>
>> Regards
>> Mayooran
>>
>> [[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.

-- 
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] Only change one parameter(n times) in R function then get outputs (n times)

2019-06-09 Thread Bert Gunter
Yes. Spend some time with some R tutorials to learn the basics of R
programming.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Jun 9, 2019 at 3:14 PM Thevaraja, Mayooran 
wrote:

> Hello Friends,
>   I have my own written an R function comparison
> (p,d,N). I need to get output corresponding changes in p while d and N are
> fixed. Also, my output is given three values such as A, B and C. Suppose if
> I change ten different p's values, we will get ten values of A, B and C. My
> goal is I want to draw the curve A vs B, C. Anyone have any ideas? I am
> trying mapply function.
>
>
> Regards
> Mayooran
>
> [[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] Only change one parameter(n times) in R function then get outputs (n times)

2019-06-09 Thread Thevaraja, Mayooran
Hello Friends,
  I have my own written an R function comparison (p,d,N). I 
need to get output corresponding changes in p while d and N are fixed. Also, my 
output is given three values such as A, B and C. Suppose if I change ten 
different p's values, we will get ten values of A, B and C. My goal is I want 
to draw the curve A vs B, C. Anyone have any ideas? I am trying mapply function.


Regards
Mayooran

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

2019-04-03 Thread J C Nash
I was about to reply to the item with a similar msg as Bert, but then
realized that the students were pointing out that the function (possibly
less than perfectly documented -- I didn't check) only works for complete
years. I've encountered that issue myself when teaching forecasting. So
I was prepared to accept the item more as a feature request or at least
a documentation request.

It would, of course, be useful for both homework and research use to have
a function able to do partial year forecasts, and I suspect there is that
capability in R somewhere. I've built custom scripts for that, but more than
a decade and a half ago. It takes time and care.

JN

On 2019-04-03 3:57 p.m., Bert Gunter wrote:
> This list has *no homework* policy. I would assume that the purpose of your
> "project" is for you to learn how to deal with exactly the sorts of issues
> you describe.
> 
> (But you might get lucky with a response anyway).
> 
> Bert Gunter
> 
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> 
> 
> On Wed, Apr 3, 2019 at 12:48 PM Michaela Berndl  wrote:
> 
>> Dear Sir or Madam,
>>
>>
>>
>> we are statistic students at the Johannes Kepler University in Linz,
>> Austria.
>>
>> In a project we had to analyse the time series influenza from the package
>> tscount and make a prediction for one year. For the prediction we used the
>> function predict from the package raster.
>>
>> Since our data ends not at the end of a year, but at week 23 in the year
>> 2012, we need to predict till the 23th week of 2013.
>>
>>
>>
>> As identified in the Figure (boxplot of the original data) attached, in the
>> first months of
>>
>> every year the recorded cases were always higher than in the rest of the
>> year.
>>
>> The other figure shows the prediction with three models (the 3 colored
>> lines) from week 23 in the year 2012 to week 22 in the year 2013 and the
>> original data (the black line) for the same time. Due to the fact that the
>> the peaks of the prediction lines are not even close to the original data,
>> we are not sure whether the predict function is correct. We suspect that
>> the predict function just works for a prediction of exactly one year, which
>> starts at week 1 and ends at week 52.
>>
>>
>>
>>
>>
>> Kind regards,
>> Doris Kuttner, Michaela Berndl
>> __
>> 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-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 predict

2019-04-03 Thread Bert Gunter
This list has *no homework* policy. I would assume that the purpose of your
"project" is for you to learn how to deal with exactly the sorts of issues
you describe.

(But you might get lucky with a response anyway).

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Wed, Apr 3, 2019 at 12:48 PM Michaela Berndl  wrote:

> Dear Sir or Madam,
>
>
>
> we are statistic students at the Johannes Kepler University in Linz,
> Austria.
>
> In a project we had to analyse the time series influenza from the package
> tscount and make a prediction for one year. For the prediction we used the
> function predict from the package raster.
>
> Since our data ends not at the end of a year, but at week 23 in the year
> 2012, we need to predict till the 23th week of 2013.
>
>
>
> As identified in the Figure (boxplot of the original data) attached, in the
> first months of
>
> every year the recorded cases were always higher than in the rest of the
> year.
>
> The other figure shows the prediction with three models (the 3 colored
> lines) from week 23 in the year 2012 to week 22 in the year 2013 and the
> original data (the black line) for the same time. Due to the fact that the
> the peaks of the prediction lines are not even close to the original data,
> we are not sure whether the predict function is correct. We suspect that
> the predict function just works for a prediction of exactly one year, which
> starts at week 1 and ends at week 52.
>
>
>
>
>
> Kind regards,
> Doris Kuttner, Michaela Berndl
> __
> 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] function predict

2019-04-03 Thread Michaela Berndl
Dear Sir or Madam,



we are statistic students at the Johannes Kepler University in Linz,
Austria.

In a project we had to analyse the time series influenza from the package
tscount and make a prediction for one year. For the prediction we used the
function predict from the package raster.

Since our data ends not at the end of a year, but at week 23 in the year
2012, we need to predict till the 23th week of 2013.



As identified in the Figure (boxplot of the original data) attached, in the
first months of

every year the recorded cases were always higher than in the rest of the
year.

The other figure shows the prediction with three models (the 3 colored
lines) from week 23 in the year 2012 to week 22 in the year 2013 and the
original data (the black line) for the same time. Due to the fact that the
the peaks of the prediction lines are not even close to the original data,
we are not sure whether the predict function is correct. We suspect that
the predict function just works for a prediction of exactly one year, which
starts at week 1 and ends at week 52.





Kind regards,
Doris Kuttner, Michaela Berndl
__
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 work inside loop but works outside

2019-03-05 Thread Ek Esawi
Thank you Peter. That's a dumb question on my part! At least i should
have known that i need an assignment statement.

Thanks again--EK

On Tue, Mar 5, 2019 at 11:36 AM peter dalgaard  wrote:
>
> You need a print() around the gsub(...) when inside a loop.
>
> -pd
>
> > On 5 Mar 2019, at 17:18 , Ek Esawi  wrote:
> >
> > Hi All,
> >
> > I am using xlsx package to extract and clean data from an Excel
> > Workbook. I ran into a strange behavior that I don’t understand. The
> > gsub doesn’t work inside the loop but does outside the loop as shown
> > on my code.. Tried to Google for help but nothing came up.
> >
> > My code loads and reads data from sheets in the workbook as a list of
> > data frames and assign them names. I wanted to replace the numbers
> > with spaces inside each part of the description column on each data
> > frame using gsub.
> >
> > Example data:
> > Datedescription   number
> > 12/12/12  234BBB1
> > 1/3/12  65bb35ff  2
> > 2/7/13  234abababab 3
> >
> > I want to have the description column to be like this.
> >    BBB
> >   Cccc bb ff
> >  abababab
> >
> > My code
> >
> > MyFile <- "C:/Users/name/Documents/Testing2.xlsx"
> > MyWBook <- loadWorkbook(MyFile)
> > MySNames <- list(names(getSheets (MyWBook)))
> > NumSheets <- length(getSheets(MyWBook))
> >
> > for (i in 1:NumSheets) {
> >  MySNames[[i]]
> > <-read.xlsx(MyFile,i,as.data.frame=TRUE,header=TRUE,keepFormulas=FALSE,stringsAsFactors=FALSE)
> >  gsub("'|-|[0-9]","",MySNames[[i]]$Description)
> > }
> >
> > The gsub function above doesn’t work, but when I tried the function
> > outside the loops, as shown below, it worked.
> > gsub("'|-|[0-9]","",MySNames[[2]]$Description)
> >
> >
> > Thanks  in advance--EK
> >
> > __
> > 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.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@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] Function doesn't work inside loop but works outside

2019-03-05 Thread peter dalgaard
You need a print() around the gsub(...) when inside a loop.

-pd

> On 5 Mar 2019, at 17:18 , Ek Esawi  wrote:
> 
> Hi All,
> 
> I am using xlsx package to extract and clean data from an Excel
> Workbook. I ran into a strange behavior that I don’t understand. The
> gsub doesn’t work inside the loop but does outside the loop as shown
> on my code.. Tried to Google for help but nothing came up.
> 
> My code loads and reads data from sheets in the workbook as a list of
> data frames and assign them names. I wanted to replace the numbers
> with spaces inside each part of the description column on each data
> frame using gsub.
> 
> Example data:
> Datedescription   number
> 12/12/12  234BBB1
> 1/3/12  65bb35ff  2
> 2/7/13  234abababab 3
> 
> I want to have the description column to be like this.
>    BBB
>   Cccc bb ff
>  abababab
> 
> My code
> 
> MyFile <- "C:/Users/name/Documents/Testing2.xlsx"
> MyWBook <- loadWorkbook(MyFile)
> MySNames <- list(names(getSheets (MyWBook)))
> NumSheets <- length(getSheets(MyWBook))
> 
> for (i in 1:NumSheets) {
>  MySNames[[i]]
> <-read.xlsx(MyFile,i,as.data.frame=TRUE,header=TRUE,keepFormulas=FALSE,stringsAsFactors=FALSE)
>  gsub("'|-|[0-9]","",MySNames[[i]]$Description)
> }
> 
> The gsub function above doesn’t work, but when I tried the function
> outside the loops, as shown below, it worked.
> gsub("'|-|[0-9]","",MySNames[[2]]$Description)
> 
> 
> Thanks  in advance--EK
> 
> __
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@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.


[R] Function doesn't work inside loop but works outside

2019-03-05 Thread Ek Esawi
Hi All,

I am using xlsx package to extract and clean data from an Excel
Workbook. I ran into a strange behavior that I don’t understand. The
gsub doesn’t work inside the loop but does outside the loop as shown
on my code.. Tried to Google for help but nothing came up.

My code loads and reads data from sheets in the workbook as a list of
data frames and assign them names. I wanted to replace the numbers
with spaces inside each part of the description column on each data
frame using gsub.

Example data:
Datedescription   number
12/12/12  234BBB1
1/3/12  65bb35ff  2
2/7/13  234abababab 3

I want to have the description column to be like this.
    BBB
   Cccc bb ff
  abababab

My code

MyFile <- "C:/Users/name/Documents/Testing2.xlsx"
MyWBook <- loadWorkbook(MyFile)
MySNames <- list(names(getSheets (MyWBook)))
NumSheets <- length(getSheets(MyWBook))

for (i in 1:NumSheets) {
  MySNames[[i]]
<-read.xlsx(MyFile,i,as.data.frame=TRUE,header=TRUE,keepFormulas=FALSE,stringsAsFactors=FALSE)
  gsub("'|-|[0-9]","",MySNames[[i]]$Description)
}

The gsub function above doesn’t work, but when I tried the function
outside the loops, as shown below, it worked.
gsub("'|-|[0-9]","",MySNames[[2]]$Description)


Thanks  in advance--EK

__
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 in default parameter value closing over variables defined later in the enclosing function

2019-01-26 Thread Ivan Krylov
On Thu, 24 Jan 2019 06:53:20 -0800
Jeff Newmiller  wrote:

> It would be better to also make secret an argument to outside instead
> of a local variable or to give up on supplying the inside function as
> an argument.

This was in a small, mostly self-contained one-off script that tested
different design of experiment approaches with simulated datasets.

Actually, I should move the "secret" variable to the global level,
together with other global settings like the dataset size and noise
level. There it's accessible to both any functions that might be
interested in it and the user who might want to change it, after all.

-- 
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] Function in default parameter value closing over variables defined later in the enclosing function

2019-01-24 Thread Jeff Newmiller
My objection to this design pattern is that this gives the default 
implementation of inside an ability that cannot be altered using functions 
provided by the caller. You might think this is what you want now but it has 
the potential to render the code unreusable in the future, which renders the 
whole idea of making inside an argument to outside pointless. It would be 
better to also make secret an argument to outside instead of a local variable 
or to give up on supplying the inside function as an argument.

On January 24, 2019 6:39:49 AM PST, Ivan Krylov  wrote:
>Dear Jan & Duncan,
>
>Thanks for your replies!
>
>On Wed, 23 Jan 2019 09:56:25 -0500
>Duncan Murdoch  wrote:
>
>> Defaults of variables are evaluated in the evaluation frame of the
>> call. So the inside() function is created in the evaluation frame,
>> and it's environment will be that frame.
> 
>> When it is called it will create a new evaluation frame (empty in
>> your example), with a parent being its environment, i.e. the
>> evaluation frame from when it was created, so it will be able to see
>> your secret variable.
>
>Nice explanation about closures in R inheriting not only their
>explicitly captured variables, but whole environments of evaluation
>(not stack) frames where they have been created.
>
>> in my opinion it would be fine to write it as
>> 
>>   outside <- function(inside = defaultInsideFn) {
>>  defaultInsideFn <- function() print(secret)
>>  secret <- 'secret'
>>  inside()
>>   }
>
>I like this idea; I'm going to use it.

-- 
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] Function in default parameter value closing over variables defined later in the enclosing function

2019-01-24 Thread Ivan Krylov
Dear Jan & Duncan,

Thanks for your replies!

On Wed, 23 Jan 2019 09:56:25 -0500
Duncan Murdoch  wrote:

> Defaults of variables are evaluated in the evaluation frame of the
> call. So the inside() function is created in the evaluation frame,
> and it's environment will be that frame.
 
> When it is called it will create a new evaluation frame (empty in
> your example), with a parent being its environment, i.e. the
> evaluation frame from when it was created, so it will be able to see
> your secret variable.

Nice explanation about closures in R inheriting not only their
explicitly captured variables, but whole environments of evaluation
(not stack) frames where they have been created.

> in my opinion it would be fine to write it as
> 
>   outside <- function(inside = defaultInsideFn) {
>  defaultInsideFn <- function() print(secret)
>  secret <- 'secret'
>  inside()
>   }

I like this idea; I'm going to use it.

-- 
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] Function in default parameter value closing over variables defined later in the enclosing function

2019-01-23 Thread Jan T Kim via R-help
Hi Duncan,

On Wed, Jan 23, 2019 at 10:02:00AM -0500, Duncan Murdoch wrote:
> On 23/01/2019 5:27 a.m., Jan T Kim wrote:
> >Hi Ivan & All,
> >
> >R's scoping system basically goes to all environments along the call
> >stack when trying to resolve an unbound variable, see the language
> >definition [1], section 4.3.4, and perhaps also 2.1.5.
> 
> You are misinterpreting that section.  It's not the call stack that is
> searched, it's the chain of environments that starts with the evaluation
> frame of the current function.  Those are very different.

yes -- I meant the environment chain but mistakenly wrote "call stack",
sorry. Thanks for pointing this out.

Best regards, Jan


> For example,
> 
> 
> g <- function() {
>   print(secret)
> }
> 
> f <- function() {
>   secret <- "secret"
>   g()
> }
> 
> would fail, because even though secret is defined in the caller of g() and
> is therefore in the call stack, that's irrelevant:  it's not in g's
> evaluation frame (which has no variables) or its parent (which is the global
> environment if those definitions were evaluated there).
> 
> Duncan Murdoch
> 
> >
> >Generally, unbound variables should be used with care. It's a bit
> >difficult to decide whether and how the code should be rewritten,
> >I'd say that depends on the underlying intentions / purposes. As it
> >is, the code could be simplified to just
> >
> > print("secret");
> >
> >but that's probably missing the point.
> >
> >Best regards, Jan
> >
> >
> >[1] https://cran.r-project.org/doc/manuals/r-release/R-lang.html
> >
> >On Wed, Jan 23, 2019 at 12:53:01PM +0300, Ivan Krylov wrote:
> >>Hi!
> >>
> >>I needed to generalize a loss function being optimized inside another
> >>function, so I made it a function argument with a default value. It
> >>worked without problems, but later I noticed that the inner function,
> >>despite being defined in the function arguments, somehow closes over a
> >>variable belonging to the outer function, which is defined later.
> >>
> >>Example:
> >>
> >>outside <- function(inside = function() print(secret)) {
> >>secret <- 'secret'
> >>inside()
> >>}
> >>outside()
> >>
> >>I'm used to languages that have both lambdas and variable declaration
> >>(like perl5 -Mstrict or C++11), so I was a bit surprised.
> >>
> >>Does this work because R looks up the variable by name late enough at
> >>runtime for the `secret` variable to exist in the parent environment of
> >>the `inside` function? Can I rely on it? Is this considered bad style?
> >>Should I rewrite it (and how)?
> >>
> >>-- 
> >>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.
> >
> >__
> >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-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 in default parameter value closing over variables defined later in the enclosing function

2019-01-23 Thread Duncan Murdoch

On 23/01/2019 5:27 a.m., Jan T Kim wrote:

Hi Ivan & All,

R's scoping system basically goes to all environments along the call
stack when trying to resolve an unbound variable, see the language
definition [1], section 4.3.4, and perhaps also 2.1.5.


You are misinterpreting that section.  It's not the call stack that is 
searched, it's the chain of environments that starts with the evaluation 
frame of the current function.  Those are very different.  For example,



g <- function() {
  print(secret)
}

f <- function() {
  secret <- "secret"
  g()
}

would fail, because even though secret is defined in the caller of g() 
and is therefore in the call stack, that's irrelevant:  it's not in g's 
evaluation frame (which has no variables) or its parent (which is the 
global environment if those definitions were evaluated there).


Duncan Murdoch



Generally, unbound variables should be used with care. It's a bit
difficult to decide whether and how the code should be rewritten,
I'd say that depends on the underlying intentions / purposes. As it
is, the code could be simplified to just

 print("secret");

but that's probably missing the point.

Best regards, Jan


[1] https://cran.r-project.org/doc/manuals/r-release/R-lang.html

On Wed, Jan 23, 2019 at 12:53:01PM +0300, Ivan Krylov wrote:

Hi!

I needed to generalize a loss function being optimized inside another
function, so I made it a function argument with a default value. It
worked without problems, but later I noticed that the inner function,
despite being defined in the function arguments, somehow closes over a
variable belonging to the outer function, which is defined later.

Example:

outside <- function(inside = function() print(secret)) {
secret <- 'secret'
inside()
}
outside()

I'm used to languages that have both lambdas and variable declaration
(like perl5 -Mstrict or C++11), so I was a bit surprised.

Does this work because R looks up the variable by name late enough at
runtime for the `secret` variable to exist in the parent environment of
the `inside` function? Can I rely on it? Is this considered bad style?
Should I rewrite it (and how)?

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


__
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] Function in default parameter value closing over variables defined later in the enclosing function

2019-01-23 Thread Duncan Murdoch

On 23/01/2019 4:53 a.m., Ivan Krylov wrote:

Hi!

I needed to generalize a loss function being optimized inside another
function, so I made it a function argument with a default value. It
worked without problems, but later I noticed that the inner function,
despite being defined in the function arguments, somehow closes over a
variable belonging to the outer function, which is defined later.

Example:

outside <- function(inside = function() print(secret)) {
secret <- 'secret'
inside()
}
outside()

I'm used to languages that have both lambdas and variable declaration
(like perl5 -Mstrict or C++11), so I was a bit surprised.


Defaults of variables are evaluated in the evaluation frame of the call.
So the inside() function is created in the evaluation frame, and it's 
environment will be that frame.


When it is called it will create a new evaluation frame (empty in your 
example), with a parent being its environment, i.e. the evaluation frame 
from when it was created, so it will be able to see your secret variable.


If it made an assignment to secret using standard "<-" assignment, it 
would create a new variable in its own evaluation frame, but if it used 
superassignment "<<-", it would modify the original secret variable.




Does this work because R looks up the variable by name late enough at
runtime for the `secret` variable to exist in the parent environment of
the `inside` function? Can I rely on it? Is this considered bad style?
Should I rewrite it (and how)?


I would consider it bad style if the inside() function had anything 
other than a trivial definition as in your example.  However, in my 
opinion it would be fine to write it as


 outside <- function(inside = defaultInsideFn) {
defaultInsideFn <- function() print(secret)
secret <- 'secret'
inside()
 }

which is essentially equivalent, other than having a shorter header on 
the outside() function.


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] Function in default parameter value closing over variables defined later in the enclosing function

2019-01-23 Thread Jan T Kim
Hi Ivan & All,

R's scoping system basically goes to all environments along the call
stack when trying to resolve an unbound variable, see the language
definition [1], section 4.3.4, and perhaps also 2.1.5.

Generally, unbound variables should be used with care. It's a bit
difficult to decide whether and how the code should be rewritten,
I'd say that depends on the underlying intentions / purposes. As it
is, the code could be simplified to just

print("secret");

but that's probably missing the point.

Best regards, Jan


[1] https://cran.r-project.org/doc/manuals/r-release/R-lang.html

On Wed, Jan 23, 2019 at 12:53:01PM +0300, Ivan Krylov wrote:
> Hi!
> 
> I needed to generalize a loss function being optimized inside another
> function, so I made it a function argument with a default value. It
> worked without problems, but later I noticed that the inner function,
> despite being defined in the function arguments, somehow closes over a
> variable belonging to the outer function, which is defined later.
> 
> Example:
> 
> outside <- function(inside = function() print(secret)) {
>   secret <- 'secret'
>   inside()
> }
> outside()
> 
> I'm used to languages that have both lambdas and variable declaration
> (like perl5 -Mstrict or C++11), so I was a bit surprised.
> 
> Does this work because R looks up the variable by name late enough at
> runtime for the `secret` variable to exist in the parent environment of
> the `inside` function? Can I rely on it? Is this considered bad style? 
> Should I rewrite it (and how)?
> 
> -- 
> 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.

__
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] Function in default parameter value closing over variables defined later in the enclosing function

2019-01-23 Thread Ivan Krylov
Hi!

I needed to generalize a loss function being optimized inside another
function, so I made it a function argument with a default value. It
worked without problems, but later I noticed that the inner function,
despite being defined in the function arguments, somehow closes over a
variable belonging to the outer function, which is defined later.

Example:

outside <- function(inside = function() print(secret)) {
secret <- 'secret'
inside()
}
outside()

I'm used to languages that have both lambdas and variable declaration
(like perl5 -Mstrict or C++11), so I was a bit surprised.

Does this work because R looks up the variable by name late enough at
runtime for the `secret` variable to exist in the parent environment of
the `inside` function? Can I rely on it? Is this considered bad style? 
Should I rewrite it (and how)?

-- 
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] Function for displaying arbitrary text as in 'help'.

2019-01-02 Thread Duncan Murdoch

On 02/01/2019 1:36 p.m., Nicolás San Martín wrote:

In this case I am not able to store the text in a file, because it could be
modified at any time and I need to display the most recent version (I fetch
it from the internet). But I can assume that it is correctly organized for
displaying.


It is possible to have dynamic content in help pages.  Web pages (e.g. 
generated using R-markdown or Shiny) are even more flexible for content, 
but maybe not meeting your requirement for displaying in an ESS buffer 
or Linux terminal window.


Duncan Murdoch



El mié., 2 ene. 2019 a las 14:31, Jeff Newmiller ()
escribió:


You can probably cobble together something, but spitting large chunks of
information at users when the program wants to is bad design. It would be
better to make a vignette or help file in a package and put the associated
code from which you had been planning to spit out that text.

On January 2, 2019 5:47:52 AM PST, "Nicolás San Martín" <
smnico...@gmail.com> wrote:

Hi all,

I am looking for a function that receives some text (any text) and
displays
it to the user in the same way as the 'help' function does. Unlike
'cat',
that outputs the text in the current window, the one I'm looking for
should
work as 'help' that, for example, in emacs ess opens a new buffer, in
the
linux terminar displays it as the more command, etc. Is there any
function
that does this?

   [[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-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 for displaying arbitrary text as in 'help'.

2019-01-02 Thread Nicolás San Martín
In this case I am not able to store the text in a file, because it could be
modified at any time and I need to display the most recent version (I fetch
it from the internet). But I can assume that it is correctly organized for
displaying.

El mié., 2 ene. 2019 a las 14:31, Jeff Newmiller ()
escribió:

> You can probably cobble together something, but spitting large chunks of
> information at users when the program wants to is bad design. It would be
> better to make a vignette or help file in a package and put the associated
> code from which you had been planning to spit out that text.
>
> On January 2, 2019 5:47:52 AM PST, "Nicolás San Martín" <
> smnico...@gmail.com> wrote:
> >Hi all,
> >
> >I am looking for a function that receives some text (any text) and
> >displays
> >it to the user in the same way as the 'help' function does. Unlike
> >'cat',
> >that outputs the text in the current window, the one I'm looking for
> >should
> >work as 'help' that, for example, in emacs ess opens a new buffer, in
> >the
> >linux terminar displays it as the more command, etc. Is there any
> >function
> >that does this?
> >
> >   [[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] Function for displaying arbitrary text as in 'help'.

2019-01-02 Thread Nicolás San Martín
Yes, the file.show() is good enough. Thanks

El mié., 2 ene. 2019 a las 13:48, Duncan Murdoch ()
escribió:

> On 02/01/2019 8:47 a.m., Nicolás San Martín wrote:
> > Hi all,
> >
> > I am looking for a function that receives some text (any text) and
> displays
> > it to the user in the same way as the 'help' function does. Unlike 'cat',
> > that outputs the text in the current window, the one I'm looking for
> should
> > work as 'help' that, for example, in emacs ess opens a new buffer, in the
> > linux terminar displays it as the more command, etc. Is there any
> function
> > that does this?
> >
>
> The file.show() function will display a text file without all the bells
> and whistles of the help system; maybe it will be good enough.
>
> 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] Function for displaying arbitrary text as in 'help'.

2019-01-02 Thread Jeff Newmiller
You can probably cobble together something, but spitting large chunks of 
information at users when the program wants to is bad design. It would be 
better to make a vignette or help file in a package and put the associated code 
from which you had been planning to spit out that text.

On January 2, 2019 5:47:52 AM PST, "Nicolás San Martín"  
wrote:
>Hi all,
>
>I am looking for a function that receives some text (any text) and
>displays
>it to the user in the same way as the 'help' function does. Unlike
>'cat',
>that outputs the text in the current window, the one I'm looking for
>should
>work as 'help' that, for example, in emacs ess opens a new buffer, in
>the
>linux terminar displays it as the more command, etc. Is there any
>function
>that does this?
>
>   [[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.


Re: [R] Function for displaying arbitrary text as in 'help'.

2019-01-02 Thread Duncan Murdoch

On 02/01/2019 8:47 a.m., Nicolás San Martín wrote:

Hi all,

I am looking for a function that receives some text (any text) and displays
it to the user in the same way as the 'help' function does. Unlike 'cat',
that outputs the text in the current window, the one I'm looking for should
work as 'help' that, for example, in emacs ess opens a new buffer, in the
linux terminar displays it as the more command, etc. Is there any function
that does this?



The file.show() function will display a text file without all the bells 
and whistles of the help system; maybe it will be good enough.


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] Function for displaying arbitrary text as in 'help'.

2019-01-02 Thread Duncan Murdoch

On 02/01/2019 8:47 a.m., Nicolás San Martín wrote:

Hi all,

I am looking for a function that receives some text (any text) and displays
it to the user in the same way as the 'help' function does. Unlike 'cat',
that outputs the text in the current window, the one I'm looking for should
work as 'help' that, for example, in emacs ess opens a new buffer, in the
linux terminar displays it as the more command, etc. Is there any function
that does this?


Help is printed by the function

 utils:::print.help_files_with_topic

which is quite a long function because of all the possible ways to 
display help.  You might be able to adapt it to your own needs, though 
it won't be trivial.


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.


[R] Function for displaying arbitrary text as in 'help'.

2019-01-02 Thread Nicolás San Martín
Hi all,

I am looking for a function that receives some text (any text) and displays
it to the user in the same way as the 'help' function does. Unlike 'cat',
that outputs the text in the current window, the one I'm looking for should
work as 'help' that, for example, in emacs ess opens a new buffer, in the
linux terminar displays it as the more command, etc. Is there any function
that does this?

[[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 gutenberg_download in the gutenbergr package

2018-01-24 Thread Jeff Newmiller
I have never used that package, but it seems obvious to me that you need to 
"reflect" on the meaning of the word "mirror". There is no reason to assume 
that a site hosting a mirror of the CRAN archive is also going to host a mirror 
of Project Gutenberg [1].

If, after you know you are giving reasonable inputs the package does not seem 
to work as designed, please remember that contributed packages have maintainers 
[2] and not all of them subscribe to r-help.

[1] https://www.gutenberg.org/MIRRORS.ALL
[2] ?maintainer
-- 
Sent from my phone. Please excuse my brevity.

On January 23, 2018 11:23:06 PM PST, Patrick Connolly 
 wrote:
>
>I've been working through https://www.tidytextmining.com/tidytext.html
>wherein everything worked until I got to this part in section 1.5
>
>> hgwells <- gutenberg_download(c(35, 36, 5230, 159))
>Determining mirror for Project Gutenberg from
>http://www.gutenberg.org/robot/harvest
>Error in open.connection(con, "rb") : 
>  Failed to connect to www.gutenberg.org port 80: Connection timed out
>
>Which indicates the problem is at the very start:
>
>  if (is.null(mirror)) {
>mirror <- gutenberg_get_mirror(verbose = verbose)
>  }
>
>The documentation for gutenberg_get_mirror indicates there's nothing
>different I could set.
>
>So I tried specifying my usual mirror:
>
>> hgwells <- gutenberg_download(c(1260, 768, 969, 9182, 767), mirror =
>"http://cran.stat.auckland.ac.nz";)
>Error in read_zip_url(full_url) : could not find function
>"read_zip_url"
>> 
>
>Which is, indeed, strange since according to 
>
>> help.search("read_zip_url")
>Help files with alias or concept or title matching ‘read_zip_url’ using
>regular expression matching:
>
>
>gutenbergr::read_zip_url
>Read a file from a .zip URL
>  Aliases: read_zip_url
>
>[...]
>
>And according to 
>library(help = "gutenbergr")
>
>[...]
>Index:
>
>gutenberg_authors   Metadata about Project Gutenberg authors
>gutenberg_download  Download one or more works using a Project
>Gutenberg ID
>gutenberg_get_mirrorGet the recommended mirror for Gutenberg files
>gutenberg_metadata  Gutenberg metadata about each work
>gutenberg_strip Strip header and footer content from a Project
>Gutenberg book
>gutenberg_subjects  Gutenberg metadata about the subject of each
>work
>gutenberg_works Get a filtered table of Gutenberg work metadata
>read_zip_urlRead a file from a .zip URL
>
>[...]
>
>However, when I look at the list for that part of the search(), there
>is no read_zip_url but all the rest of that list are present.  So it's
>not surprising that it isn't found.  But it puzzles me that it is not
>there.
>
>Ideas as to where I should proceed gratefully appreciated.
>
>
>> sessionInfo()
>R version 3.4.2 (2017-09-28)
>Platform: x86_64-pc-linux-gnu (64-bit)
>Running under: Ubuntu 14.04.5 LTS
>
>Matrix products: default
>BLAS: /home/hrapgc/local/R-3.4.2/lib/libRblas.so
>LAPACK: /home/hrapgc/local/R-3.4.2/lib/libRlapack.so
>
>locale:
> [1] LC_CTYPE=en_NZ.UTF-8   LC_NUMERIC=C  
> [3] LC_TIME=en_NZ.UTF-8LC_COLLATE=en_NZ.UTF-8
> [5] LC_MONETARY=en_NZ.UTF-8LC_MESSAGES=en_NZ.UTF-8   
> [7] LC_PAPER=en_NZ.UTF-8   LC_NAME=C 
> [9] LC_ADDRESS=C   LC_TELEPHONE=C
>[11] LC_MEASUREMENT=en_NZ.UTF-8 LC_IDENTIFICATION=C   
>
>attached base packages:
>[1] grDevices utils stats graphics  methods   base 
>
>other attached packages:
>[1] sos_2.0-0  brew_1.0-6 gutenbergr_0.1.3  
>ggplot2_2.2.1 
>[5] stringr_1.2.0  bindrcpp_0.2   dplyr_0.7.4   
>janeaustenr_0.1.5 
>[9] tidytext_0.1.6 FactoMineR_1.38readxl_1.0.0   tm_0.7-3  
>   
>[13] NLP_0.1-11 wordcloud_2.5  RColorBrewer_1.1-2
>lattice_0.20-35   
>
>loaded via a namespace (and not attached):
> [1] Rcpp_0.12.13 cellranger_1.1.0 compiler_3.4.2  
> [4] plyr_1.8.4   bindr_0.1tokenizers_0.1.4
> [7] tools_3.4.2  gtable_0.2.0 tibble_1.3.4
>[10] nlme_3.1-131 pkgconfig_2.0.1  rlang_0.1.2 
>[13] Matrix_1.2-11psych_1.7.8  curl_3.0
>[16] parallel_3.4.2   xml2_1.1.1   cluster_2.0.6   
>[19] hms_0.3  flashClust_1.01-2grid_3.4.2  
>[22] scatterplot3d_0.3-40 glue_1.1.1   ellipse_0.3-8   
>[25] R6_2.2.2 foreign_0.8-69   readr_1.1.1 
>[28] purrr_0.2.4  tidyr_0.7.2  reshape2_1.4.2  
>[31] magrittr_1.5 scales_0.5.0 SnowballC_0.5.1 
>[34] MASS_7.3-47  leaps_3.0assertthat_0.2.0
>[37] mnormt_1.5-5 colorspace_1.3-2 labeling_0.3
>[40] stringi_1.1.5lazyeval_0.2.1   munsell_0.4.3   
>[43] slam_0.1-42  broom_0.4.2 
>> 
>
>-- 
>~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

[R] Function gutenberg_download in the gutenbergr package

2018-01-23 Thread Patrick Connolly

I've been working through https://www.tidytextmining.com/tidytext.html
wherein everything worked until I got to this part in section 1.5

> hgwells <- gutenberg_download(c(35, 36, 5230, 159))
Determining mirror for Project Gutenberg from 
http://www.gutenberg.org/robot/harvest
Error in open.connection(con, "rb") : 
  Failed to connect to www.gutenberg.org port 80: Connection timed out

Which indicates the problem is at the very start:

  if (is.null(mirror)) {
mirror <- gutenberg_get_mirror(verbose = verbose)
  }

The documentation for gutenberg_get_mirror indicates there's nothing
different I could set.

So I tried specifying my usual mirror:

> hgwells <- gutenberg_download(c(1260, 768, 969, 9182, 767), mirror = 
> "http://cran.stat.auckland.ac.nz";)
Error in read_zip_url(full_url) : could not find function "read_zip_url"
> 

Which is, indeed, strange since according to 

> help.search("read_zip_url")
Help files with alias or concept or title matching ‘read_zip_url’ using
regular expression matching:


gutenbergr::read_zip_url
Read a file from a .zip URL
  Aliases: read_zip_url

[...]

And according to 
library(help = "gutenbergr")

[...]
Index:

gutenberg_authors   Metadata about Project Gutenberg authors
gutenberg_download  Download one or more works using a Project
Gutenberg ID
gutenberg_get_mirrorGet the recommended mirror for Gutenberg files
gutenberg_metadata  Gutenberg metadata about each work
gutenberg_strip Strip header and footer content from a Project
Gutenberg book
gutenberg_subjects  Gutenberg metadata about the subject of each
work
gutenberg_works Get a filtered table of Gutenberg work metadata
read_zip_urlRead a file from a .zip URL

[...]

However, when I look at the list for that part of the search(), there
is no read_zip_url but all the rest of that list are present.  So it's
not surprising that it isn't found.  But it puzzles me that it is not
there.

Ideas as to where I should proceed gratefully appreciated.


> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

Matrix products: default
BLAS: /home/hrapgc/local/R-3.4.2/lib/libRblas.so
LAPACK: /home/hrapgc/local/R-3.4.2/lib/libRlapack.so

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

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

other attached packages:
 [1] sos_2.0-0  brew_1.0-6 gutenbergr_0.1.3   ggplot2_2.2.1 
 [5] stringr_1.2.0  bindrcpp_0.2   dplyr_0.7.4janeaustenr_0.1.5 
 [9] tidytext_0.1.6 FactoMineR_1.38readxl_1.0.0   tm_0.7-3  
[13] NLP_0.1-11 wordcloud_2.5  RColorBrewer_1.1-2 lattice_0.20-35   

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.13 cellranger_1.1.0 compiler_3.4.2  
 [4] plyr_1.8.4   bindr_0.1tokenizers_0.1.4
 [7] tools_3.4.2  gtable_0.2.0 tibble_1.3.4
[10] nlme_3.1-131 pkgconfig_2.0.1  rlang_0.1.2 
[13] Matrix_1.2-11psych_1.7.8  curl_3.0
[16] parallel_3.4.2   xml2_1.1.1   cluster_2.0.6   
[19] hms_0.3  flashClust_1.01-2grid_3.4.2  
[22] scatterplot3d_0.3-40 glue_1.1.1   ellipse_0.3-8   
[25] R6_2.2.2 foreign_0.8-69   readr_1.1.1 
[28] purrr_0.2.4  tidyr_0.7.2  reshape2_1.4.2  
[31] magrittr_1.5 scales_0.5.0 SnowballC_0.5.1 
[34] MASS_7.3-47  leaps_3.0assertthat_0.2.0
[37] mnormt_1.5-5 colorspace_1.3-2 labeling_0.3
[40] stringi_1.1.5lazyeval_0.2.1   munsell_0.4.3   
[43] slam_0.1-42  broom_0.4.2 
> 

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
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 pointers?

2017-11-23 Thread jim holtman
I am replying to the first part of the question about the size of the
object.  It is probably best to use the "object_size" function in the
"pryr" package:

 ‘object_size’ works similarly to ‘object.size’, but counts more
 accurately and includes the size of environments. ‘compare_size’
 makes it easy to compare the output of ‘object_size’ and
 ‘object.size’.

Here is what you get from the same code:

> N <- 1
> closureList <- vector("list", N)
> nsize = sample(x = 1:100, size = N, replace = TRUE)
> for (i in seq_along(nsize)){
+ closureList[[i]] <- list(func = rnorm, n = nsize[i])
+ }
> format(object.size(closureList), units = "Mb")
[1] "22.4 Mb"
> pryr::compare_size(closureList)
base pryr
23520040  2241776

You will notice that you get back a size that is 10X smaller because it is
accounting for the shared space.


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

On Wed, Nov 22, 2017 at 11:29 AM, Paul Johnson  wrote:

> We have a project that calls for the creation of a list of many
> distribution objects.  Distributions can be of various types, with
> various parameters, but we ran into some problems. I started testing
> on a simple list of rnorm-based objects.
>
> I was a little surprised at the RAM storage requirements, here's an
> example:
>
> N <- 1
> closureList <- vector("list", N)
> nsize = sample(x = 1:100, size = N, replace = TRUE)
> for (i in seq_along(nsize)){
> closureList[[i]] <- list(func = rnorm, n = nsize[i])
> }
> format(object.size(closureList), units = "Mb")
>
> Output says
> 22.4 MB
>
> I noticed that if I do not name the objects in the list, then the
> storage drops to 19.9 MB.
>
> That seemed like a lot of storage for a function's name. Why so much?
> My colleagues think the RAM use is high because this is a closure
> (hence closureList).  I can't even convince myself it actually is a
> closure. The R source has
>
> rnorm <- function(n, mean=0, sd=1) .Call(C_rnorm, n, mean, sd)
>
> The storage holding 1 copies of rnorm, but we really only need 1,
> which we can use in the objects.
>
> Thinking of this like C,  I am looking to pass in a pointer to the
> function.  I found my way to the idea of putting a function in an
> environment in order to pass it by reference:
>
> rnormPointer <- function(inputValue1, inputValue2){
> object <- new.env(parent=globalenv())
> object$distr <- inputValue1
> object$n <- inputValue2
> class(object) <- 'pointer'
> object
> }
>
> ## Experiment with that
> gg <- rnormPointer(rnorm, 33)
> gg$distr(gg$n)
>
> ptrList <- vector("list", N)
> for(i in seq_along(nsize)) {
> ptrList[[i]] <- rnormPointer(rnorm, nsize[i])
> }
> format(object.size(ptrList), units = "Mb")
>
> The required storage is reduced to 2.6 Mb. Thats 1/10 of the RAM
> required for closureList.  This thing works in the way I expect
>
> ## can pass in the unnamed arguments for n, mean and sd here
> ptrList[[1]]$distr(33, 100, 10)
> ## Or the named arguments
> ptrList[[1]]$distr(1, sd = 100)
>
> This environment trick mostly works, so far as I can see, but I have
> these questions.
>
> 1. Is the object.size() return accurate for ptrList?  Do I really
> reduce storage to that amount, or is the required storage someplace
> else (in the new environment) that is not included in object.size()?
>
> 2. Am I running with scissors here? Unexpected bad things await?
>
> 3. Why is the storage for closureList so great? It looks to me like
> rnorm is just this little thing:
>
> function (n, mean = 0, sd = 1)
> .Call(C_rnorm, n, mean, sd)
> 
>
> 4. Could I learn (you show me?) to store the bytecode address as a
> thing and use it in the objects?  I'd guess that is the fastest
> possible way. In an Objective-C problem in the olden days, we found
> the method-lookup was a major slowdown and one of the programmers
> showed us how to save the lookup and use it over and over.
>
> pj
>
>
>
> --
> Paul E. Johnson   http://pj.freefaculty.org
> Director, Center for Research Methods and Data Analysis
> http://crmda.ku.edu
>
> To write to me directly, please address me at pauljohn at ku.edu.
>
> __
> 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 pointers?

2017-11-22 Thread Duncan Murdoch

On 22/11/2017 11:29 AM, Paul Johnson wrote:

We have a project that calls for the creation of a list of many
distribution objects.  Distributions can be of various types, with
various parameters, but we ran into some problems. I started testing
on a simple list of rnorm-based objects.

I was a little surprised at the RAM storage requirements, here's an example:

N <- 1
closureList <- vector("list", N)
nsize = sample(x = 1:100, size = N, replace = TRUE)
for (i in seq_along(nsize)){
 closureList[[i]] <- list(func = rnorm, n = nsize[i])
}
format(object.size(closureList), units = "Mb")

Output says
22.4 MB



You should read the help page for object.size.  You're doing exactly the 
kind of thing that causes it to give overestimates of the amount of 
memory being used.


I'd suggest turning on memory profiling in Rprof() for a more accurate 
result, but it seems to be broken:


> Rprof(memory.profiling=TRUE)
> N <- 1
> closureList <- vector("list", N)
> nsize = sample(x = 1:100, size = N, replace = TRUE)
> for (i in seq_along(nsize)){
+ closureList[[i]] <- list(func = rnorm, n = nsize[i])
+ }
> format(object.size(closureList), units = "Mb")
[1] "19.2 Mb"
> Rprof(NULL)
> summaryRprof()
Error in rowsum.default(c(as.vector(new.ftable), fcounts), 
c(names(new.ftable),  :

  unimplemented type 'NULL' in 'HashTableSetup'
In addition: Warning message:
In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'


Duncan Murdoch


I noticed that if I do not name the objects in the list, then the
storage drops to 19.9 MB.

That seemed like a lot of storage for a function's name. Why so much?
My colleagues think the RAM use is high because this is a closure
(hence closureList).  I can't even convince myself it actually is a
closure. The R source has

rnorm <- function(n, mean=0, sd=1) .Call(C_rnorm, n, mean, sd)

The storage holding 1 copies of rnorm, but we really only need 1,
which we can use in the objects.

Thinking of this like C,  I am looking to pass in a pointer to the
function.  I found my way to the idea of putting a function in an
environment in order to pass it by reference:

rnormPointer <- function(inputValue1, inputValue2){
 object <- new.env(parent=globalenv())
 object$distr <- inputValue1
 object$n <- inputValue2
 class(object) <- 'pointer'
 object
}

## Experiment with that
gg <- rnormPointer(rnorm, 33)
gg$distr(gg$n)

ptrList <- vector("list", N)
for(i in seq_along(nsize)) {
 ptrList[[i]] <- rnormPointer(rnorm, nsize[i])
}
format(object.size(ptrList), units = "Mb")

The required storage is reduced to 2.6 Mb. Thats 1/10 of the RAM
required for closureList.  This thing works in the way I expect

## can pass in the unnamed arguments for n, mean and sd here
ptrList[[1]]$distr(33, 100, 10)
## Or the named arguments
ptrList[[1]]$distr(1, sd = 100)

This environment trick mostly works, so far as I can see, but I have
these questions.

1. Is the object.size() return accurate for ptrList?  Do I really
reduce storage to that amount, or is the required storage someplace
else (in the new environment) that is not included in object.size()?

2. Am I running with scissors here? Unexpected bad things await?

3. Why is the storage for closureList so great? It looks to me like
rnorm is just this little thing:

function (n, mean = 0, sd = 1)
.Call(C_rnorm, n, mean, sd)


4. Could I learn (you show me?) to store the bytecode address as a
thing and use it in the objects?  I'd guess that is the fastest
possible way. In an Objective-C problem in the olden days, we found
the method-lookup was a major slowdown and one of the programmers
showed us how to save the lookup and use it over and over.

pj





__
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] function pointers?

2017-11-22 Thread Paul Johnson
We have a project that calls for the creation of a list of many
distribution objects.  Distributions can be of various types, with
various parameters, but we ran into some problems. I started testing
on a simple list of rnorm-based objects.

I was a little surprised at the RAM storage requirements, here's an example:

N <- 1
closureList <- vector("list", N)
nsize = sample(x = 1:100, size = N, replace = TRUE)
for (i in seq_along(nsize)){
closureList[[i]] <- list(func = rnorm, n = nsize[i])
}
format(object.size(closureList), units = "Mb")

Output says
22.4 MB

I noticed that if I do not name the objects in the list, then the
storage drops to 19.9 MB.

That seemed like a lot of storage for a function's name. Why so much?
My colleagues think the RAM use is high because this is a closure
(hence closureList).  I can't even convince myself it actually is a
closure. The R source has

rnorm <- function(n, mean=0, sd=1) .Call(C_rnorm, n, mean, sd)

The storage holding 1 copies of rnorm, but we really only need 1,
which we can use in the objects.

Thinking of this like C,  I am looking to pass in a pointer to the
function.  I found my way to the idea of putting a function in an
environment in order to pass it by reference:

rnormPointer <- function(inputValue1, inputValue2){
object <- new.env(parent=globalenv())
object$distr <- inputValue1
object$n <- inputValue2
class(object) <- 'pointer'
object
}

## Experiment with that
gg <- rnormPointer(rnorm, 33)
gg$distr(gg$n)

ptrList <- vector("list", N)
for(i in seq_along(nsize)) {
ptrList[[i]] <- rnormPointer(rnorm, nsize[i])
}
format(object.size(ptrList), units = "Mb")

The required storage is reduced to 2.6 Mb. Thats 1/10 of the RAM
required for closureList.  This thing works in the way I expect

## can pass in the unnamed arguments for n, mean and sd here
ptrList[[1]]$distr(33, 100, 10)
## Or the named arguments
ptrList[[1]]$distr(1, sd = 100)

This environment trick mostly works, so far as I can see, but I have
these questions.

1. Is the object.size() return accurate for ptrList?  Do I really
reduce storage to that amount, or is the required storage someplace
else (in the new environment) that is not included in object.size()?

2. Am I running with scissors here? Unexpected bad things await?

3. Why is the storage for closureList so great? It looks to me like
rnorm is just this little thing:

function (n, mean = 0, sd = 1)
.Call(C_rnorm, n, mean, sd)


4. Could I learn (you show me?) to store the bytecode address as a
thing and use it in the objects?  I'd guess that is the fastest
possible way. In an Objective-C problem in the olden days, we found
the method-lookup was a major slowdown and one of the programmers
showed us how to save the lookup and use it over and over.

pj



-- 
Paul E. Johnson   http://pj.freefaculty.org
Director, Center for Research Methods and Data Analysis http://crmda.ku.edu

To write to me directly, please address me at pauljohn at ku.edu.

__
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 to save results

2017-11-01 Thread Rui Barradas

Hello,

If cat is giving you an error try print(attr <- ...etc...)

Hope this helps,

Rui Barradas

Em 01-11-2017 17:21, Priya Arasu via R-help escreveu:

Hi David,Thank you for the example.When I try to use the cat function, I get an 
error

cat(attr<-getAttractors(net, type="asynchronous"))Error in cat(attr <- getAttractors(net, 
type = "asynchronous")) :
   argument 1 (type 'pairlist') cannot be handled by 'cat'

Please let me know, if I have used the function in right way?.
Thank you
Priya









 On Wednesday, 1 November 2017 9:32 PM, David L Carlson  
wrote:


  Let's try a simple example.


# Create a script file of commands
# Note we must print the results of quantile explicitly
cat("x <- rnorm(50)\nprint(quantile(x))\nstem(x)\n", file="Test.R")

# Test it by running it to the console
source("Test.R")

 0%25%50%75%  100%
-2.4736219 -0.7915433 -0.1178056  0.7023577  2.9158617

   The decimal point is at the |

   -2 | 510
   -1 | 7631110
   -0 | 998877733211
   0 | 011244889
   1 | 00045
   2 | 19



# Now run it and save the file
sink("Testout.txt")
source("Test.R")
sink()

# What is located in "Testout.txt"?
cat(readLines("Testout.txt"), sep="\n")

 0%25%50%75%100%
-2.47511893 -0.47919111  0.05761628  0.67403447  1.79825459

   The decimal point is at the |

   -2 | 5
   -2 | 4
   -1 |
   -1 | 432000
   -0 | 87755
   -0 | 442110
   0 | 001244
   0 | 556789
   1 | 113
   1 | 5788


# Success


Depending on your operating system, you may also be able to save the output 
with File | Save to File.

---
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Priya Arasu via 
R-help
Sent: Wednesday, November 1, 2017 9:57 AM
To: Eric Berger 
Cc: r-help@r-project.org
Subject: Re: [R] Function to save results

Hi Eric,Thanks for the explanation. Is there a way to save the results 
automatically after the analysis gets over?. As I recently lost the results, 
because I didn't save the results. I don't want to run the sink or save command 
after the analysis is over rather run the command for saving the file before 
starting to run the analysis, so the file gets saved automatically after the 
script has finished running Priya



 On Wednesday, 1 November 2017 7:53 PM, Eric Berger  
wrote:


  Hi Priya,
You did not follow the logic of the pseudo-code. The sink("filename"), sink() 
pair captures whatever output is generated between the first sink statement and the 
second sink statement.You need (possibly) to do:
sink("C://Users//Priya// Desktop//Attractor analysis_all genes//synaptogenesis//attr. txt") net <- 
loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all genes//synaptogenesis// regulationof_dopamine_ 
signaling_submodule3.txt")attr <- getAttractors(net, type="asynchronous")
sink()
HTH,Eric





Hi Eric,I tried as you suggested but I could not find the output in the text 
file I created (attr.txt)

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all genes//synaptogenesis// 
regulationof_dopamine_ signaling_submodule3.txt")sink("C://Users//Priya// Desktop//Attractor 
analysis_all genes//synaptogenesis//attr. txt")


sink()

attr <- getAttractors(net, type="asynchronous")
  Priya


 On Wednesday, 1 November 2017 6:54 PM, Eric Berger  
wrote:


  Some comments:1. sink() does not return a value. There is on point to set attr <- sink(...). Just 
give the command sink("C://etc")2. to complete the saving to the file you must give a 
second sink command with no argument:  sink()So your code would be (pseudo-code, not actual code) 
sink( "filename" )do something that prints output which will be captured by sinksink() 
HTH,Eric


On Wed, Nov 1, 2017 at 1:32 PM, Priya Arasu via R-help  
wrote:

Hi,I want the results to be saved automatically in a output text file after the 
script has finished running.

I used the sink function in the following example, but the results file 
(output.txt) was empty.

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all genes//synaptogenesis// 
regulationof_dopamine_ signaling_submodule3.txt")# First I loaded theinput file for which I want to 
identify attractors attr <- sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//output. txt")# used the sink function to save the results from attr function

attr <- getAttractors(net, type="asynchronous")# then ran the script for 
identifying attractors Is there any function to save the results b

Re: [R] Function to save results

2017-11-01 Thread Priya Arasu via R-help
Hi David,Thank you for the example.When I try to use the cat function, I get an 
error

cat(attr<-getAttractors(net, type="asynchronous"))Error in cat(attr <- 
getAttractors(net, type = "asynchronous")) : 
  argument 1 (type 'pairlist') cannot be handled by 'cat'

Please let me know, if I have used the function in right way?. 
Thank you
Priya






 
 

On Wednesday, 1 November 2017 9:32 PM, David L Carlson  
wrote:
 

 Let's try a simple example. 

> # Create a script file of commands
> # Note we must print the results of quantile explicitly
> cat("x <- rnorm(50)\nprint(quantile(x))\nstem(x)\n", file="Test.R")
> 
> # Test it by running it to the console
> source("Test.R")
        0%        25%        50%        75%      100% 
-2.4736219 -0.7915433 -0.1178056  0.7023577  2.9158617 

  The decimal point is at the |

  -2 | 510
  -1 | 7631110
  -0 | 998877733211
  0 | 011244889
  1 | 00045
  2 | 19

> 
> # Now run it and save the file
> sink("Testout.txt")
> source("Test.R")
> sink()
> 
> # What is located in "Testout.txt"?
> cat(readLines("Testout.txt"), sep="\n")
        0%        25%        50%        75%        100% 
-2.47511893 -0.47919111  0.05761628  0.67403447  1.79825459 

  The decimal point is at the |

  -2 | 5
  -2 | 4
  -1 | 
  -1 | 432000
  -0 | 87755
  -0 | 442110
  0 | 001244
  0 | 556789
  1 | 113
  1 | 5788

> # Success

Depending on your operating system, you may also be able to save the output 
with File | Save to File.

---
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Priya Arasu via 
R-help
Sent: Wednesday, November 1, 2017 9:57 AM
To: Eric Berger 
Cc: r-help@r-project.org
Subject: Re: [R] Function to save results

Hi Eric,Thanks for the explanation. Is there a way to save the results 
automatically after the analysis gets over?. As I recently lost the results, 
because I didn't save the results. I don't want to run the sink or save command 
after the analysis is over rather run the command for saving the file before 
starting to run the analysis, so the file gets saved automatically after the 
script has finished running Priya
 


    On Wednesday, 1 November 2017 7:53 PM, Eric Berger  
wrote:


 Hi Priya,
You did not follow the logic of the pseudo-code. The sink("filename"), sink() 
pair captures whatever output is generated between the first sink statement and 
the second sink statement.You need (possibly) to do:
sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//attr. txt") net <- loadNetwork("C://Users//Priya/ 
/Desktop//Attractor analysis_all genes//synaptogenesis// regulationof_dopamine_ 
signaling_submodule3.txt")attr <- getAttractors(net, type="asynchronous")
sink()
HTH,Eric


 


Hi Eric,I tried as you suggested but I could not find the output in the text 
file I created (attr.txt)

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ 
signaling_submodule3.txt")sink("C://Users//Priya// Desktop//Attractor 
analysis_all genes//synaptogenesis//attr. txt")


sink()

attr <- getAttractors(net, type="asynchronous")
 Priya


    On Wednesday, 1 November 2017 6:54 PM, Eric Berger  
wrote:


 Some comments:1. sink() does not return a value. There is on point to set attr 
<- sink(...). Just give the command sink("C://etc")2. to complete the 
saving to the file you must give a second sink command with no argument:  
sink()So your code would be (pseudo-code, not actual code) sink( "filename" )do 
something that prints output which will be captured by sinksink() HTH,Eric


On Wed, Nov 1, 2017 at 1:32 PM, Priya Arasu via R-help  
wrote:

Hi,I want the results to be saved automatically in a output text file after the 
script has finished running.

I used the sink function in the following example, but the results file 
(output.txt) was empty.

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ signaling_submodule3.txt")# 
First I loaded theinput file for which I want to identify attractors attr <- 
sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//output. txt")# used the sink function to save the 
results from attr function

attr <- getAttractors(net, type="asynchronous")# then ran the script for 
identifying attractors Is there any function to save the results before setting 
the script to run, so that results are automatically saved in a text file after 
the s

Re: [R] Function to save results

2017-11-01 Thread David L Carlson
No. You have not used it correctly. It was an example. Put your commands 
between the two sink functions. That will save any printed out put that results 
from those commands. It will not save attr, but you did not ask how to do that.

David C

On Nov 1, 2017 12:21 PM, Priya Arasu  wrote:
Hi David,
Thank you for the example.
When I try to use the cat function, I get an error


cat(attr<-getAttractors(net, type="asynchronous"))

Error in cat(attr <- getAttractors(net, type = "asynchronous")) :
  argument 1 (type 'pairlist') cannot be handled by 'cat'

Please let me know, if I have used the function in right way?.
Thank you
Priya











On Wednesday, 1 November 2017 9:32 PM, David L Carlson  
wrote:


Let's try a simple example.

> # Create a script file of commands
> # Note we must print the results of quantile explicitly
> cat("x <- rnorm(50)\nprint(quantile(x))\nstem(x)\n", file="Test.R")
>
> # Test it by running it to the console
> source("Test.R")
0%25%50%75%  100%
-2.4736219 -0.7915433 -0.1178056  0.7023577  2.9158617

  The decimal point is at the |

  -2 | 510
  -1 | 7631110
  -0 | 998877733211
  0 | 011244889
  1 | 00045
  2 | 19

>
> # Now run it and save the file
> sink("Testout.txt")
> source("Test.R")
> sink()
>
> # What is located in "Testout.txt"?
> cat(readLines("Testout.txt"), sep="\n")
0%25%50%75%100%
-2.47511893 -0.47919111  0.05761628  0.67403447  1.79825459

  The decimal point is at the |

  -2 | 5
  -2 | 4
  -1 |
  -1 | 432000
  -0 | 87755
  -0 | 442110
  0 | 001244
  0 | 556789
  1 | 113
  1 | 5788

> # Success

Depending on your operating system, you may also be able to save the output 
with File | Save to File.

---
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-Original Message-
From: R-help 
[mailto:r-help-boun...@r-project.org<mailto:r-help-boun...@r-project.org>] On 
Behalf Of Priya Arasu via R-help
Sent: Wednesday, November 1, 2017 9:57 AM
To: Eric Berger mailto:ericjber...@gmail.com>>
Cc: r-help@r-project.org<mailto:r-help@r-project.org>
Subject: Re: [R] Function to save results

Hi Eric,Thanks for the explanation. Is there a way to save the results 
automatically after the analysis gets over?. As I recently lost the results, 
because I didn't save the results. I don't want to run the sink or save command 
after the analysis is over rather run the command for saving the file before 
starting to run the analysis, so the file gets saved automatically after the 
script has finished running Priya



On Wednesday, 1 November 2017 7:53 PM, Eric Berger 
mailto:ericjber...@gmail.com>> wrote:


Hi Priya,
You did not follow the logic of the pseudo-code. The sink("filename"), sink() 
pair captures whatever output is generated between the first sink statement and 
the second sink statement.You need (possibly) to do:
sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//attr. txt") net <- loadNetwork("C://Users//Priya/ 
/Desktop//Attractor analysis_all genes//synaptogenesis// regulationof_dopamine_ 
signaling_submodule3.txt")attr <- getAttractors(net, type="asynchronous")
sink()
HTH,Eric



On Wed, Nov 1, 2017 at 4:10 PM, Priya Arasu 
mailto:galaxie2...@yahoo.co.in>> wrote:

Hi Eric,I tried as you suggested but I could not find the output in the text 
file I created (attr.txt)

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ 
signaling_submodule3.txt")sink("C://Users//Priya// Desktop//Attractor 
analysis_all genes//synaptogenesis//attr. txt")


sink()

attr <- getAttractors(net, type="asynchronous")
 Priya


On Wednesday, 1 November 2017 6:54 PM, Eric Berger 
mailto:ericjber...@gmail.com>> wrote:


Some comments:1. sink() does not return a value. There is on point to set attr 
<- sink(...). Just give the command sink("C://etc")2. to complete the 
saving to the file you must give a second sink command with no argument:  
sink()So your code would be (pseudo-code, not actual code) sink( "filename" )do 
something that prints output which will be captured by sinksink() HTH,Eric


On Wed, Nov 1, 2017 at 1:32 PM, Priya Arasu via R-help 
mailto:r-help@r-project.org>> wrote:

Hi,I want the results to be saved automatically in a output text file after the 
script has finished running.

I used the sink function in the following example, but the results file 
(output.txt) was empty.

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_al

Re: [R] Function to save results

2017-11-01 Thread Eric Berger
Hi Priya,
I think your original question may have been phrased in a way that caused
David and me some confusion.
I think sink() may not be the function that is appropriate in your case.
Sink() is used to capture output to the console (so to speak).
You are trying to save the results of calculations returned, in this case
in the variable 'attr'.
You need to do something like:

attr <- getAttractors( ... )
saveRDS( attr, "filename.RDS")

and then later you can read the results back in another R session:

savedAttr <- readRDS("filename.RDS")

Look at the documentation ?saveRDS and ?readRDS

HTH,
Eric

On Wed, Nov 1, 2017 at 6:02 PM, David L Carlson  wrote:

> Let's try a simple example.
>
> > # Create a script file of commands
> > # Note we must print the results of quantile explicitly
> > cat("x <- rnorm(50)\nprint(quantile(x))\nstem(x)\n", file="Test.R")
> >
> > # Test it by running it to the console
> > source("Test.R")
> 0%25%50%75%   100%
> -2.4736219 -0.7915433 -0.1178056  0.7023577  2.9158617
>
>   The decimal point is at the |
>
>   -2 | 510
>   -1 | 7631110
>   -0 | 998877733211
>0 | 011244889
>1 | 00045
>2 | 19
>
> >
> > # Now run it and save the file
> > sink("Testout.txt")
> > source("Test.R")
> > sink()
> >
> > # What is located in "Testout.txt"?
> > cat(readLines("Testout.txt"), sep="\n")
>  0% 25% 50% 75%100%
> -2.47511893 -0.47919111  0.05761628  0.67403447  1.79825459
>
>   The decimal point is at the |
>
>   -2 | 5
>   -2 | 4
>   -1 |
>   -1 | 432000
>   -0 | 87755
>   -0 | 442110
>0 | 001244
>0 | 556789
>1 | 113
>1 | 5788
>
> > # Success
>
> Depending on your operating system, you may also be able to save the
> output with File | Save to File.
>
> ---
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Priya
> Arasu via R-help
> Sent: Wednesday, November 1, 2017 9:57 AM
> To: Eric Berger 
> Cc: r-help@r-project.org
> Subject: Re: [R] Function to save results
>
> Hi Eric,Thanks for the explanation. Is there a way to save the results
> automatically after the analysis gets over?. As I recently lost the
> results, because I didn't save the results. I don't want to run the sink or
> save command after the analysis is over rather run the command for saving
> the file before starting to run the analysis, so the file gets saved
> automatically after the script has finished running Priya
>
>
>
> On Wednesday, 1 November 2017 7:53 PM, Eric Berger <
> ericjber...@gmail.com> wrote:
>
>
>  Hi Priya,
> You did not follow the logic of the pseudo-code. The sink("filename"),
> sink() pair captures whatever output is generated between the first sink
> statement and the second sink statement.You need (possibly) to do:
> sink("C://Users//Priya// Desktop//Attractor analysis_all
> genes//synaptogenesis//attr. txt") net <- loadNetwork("C://Users//Priya/
> /Desktop//Attractor analysis_all genes//synaptogenesis//
> regulationof_dopamine_ signaling_submodule3.txt")attr <- getAttractors(net,
> type="asynchronous")
> sink()
> HTH,Eric
>
>
>
> On Wed, Nov 1, 2017 at 4:10 PM, Priya Arasu 
> wrote:
>
> Hi Eric,I tried as you suggested but I could not find the output in the
> text file I created (attr.txt)
>
> net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all
> genes//synaptogenesis// regulationof_dopamine_ 
> signaling_submodule3.txt")sink("C://Users//Priya//
> Desktop//Attractor analysis_all genes//synaptogenesis//attr. txt")
>
>
> sink()
>
> attr <- getAttractors(net, type="asynchronous")
>  Priya
>
>
> On Wednesday, 1 November 2017 6:54 PM, Eric Berger <
> ericjber...@gmail.com> wrote:
>
>
>  Some comments:1. sink() does not return a value. There is on point to set
> attr <- sink(...). Just give the command sink("C://etc")2. to complete
> the saving to the file you must give a second sink command with no
> argument:  sink()So your code would be (pseudo-code, not actual code) sink(
> "filename" )do something that prints output which will be captured by
> sinksink() HTH,Eric
>
>
> On Wed, Nov 1, 2017 at 1:32 PM, Priya Arasu 

Re: [R] Function to save results

2017-11-01 Thread David L Carlson
Let's try a simple example. 

> # Create a script file of commands
> # Note we must print the results of quantile explicitly
> cat("x <- rnorm(50)\nprint(quantile(x))\nstem(x)\n", file="Test.R")
> 
> # Test it by running it to the console
> source("Test.R")
0%25%50%75%   100% 
-2.4736219 -0.7915433 -0.1178056  0.7023577  2.9158617 

  The decimal point is at the |

  -2 | 510
  -1 | 7631110
  -0 | 998877733211
   0 | 011244889
   1 | 00045
   2 | 19

> 
> # Now run it and save the file
> sink("Testout.txt")
> source("Test.R")
> sink()
> 
> # What is located in "Testout.txt"?
> cat(readLines("Testout.txt"), sep="\n")
 0% 25% 50% 75%100% 
-2.47511893 -0.47919111  0.05761628  0.67403447  1.79825459 

  The decimal point is at the |

  -2 | 5
  -2 | 4
  -1 | 
  -1 | 432000
  -0 | 87755
  -0 | 442110
   0 | 001244
   0 | 556789
   1 | 113
   1 | 5788

> # Success

Depending on your operating system, you may also be able to save the output 
with File | Save to File.

---
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Priya Arasu via 
R-help
Sent: Wednesday, November 1, 2017 9:57 AM
To: Eric Berger 
Cc: r-help@r-project.org
Subject: Re: [R] Function to save results

Hi Eric,Thanks for the explanation. Is there a way to save the results 
automatically after the analysis gets over?. As I recently lost the results, 
because I didn't save the results. I don't want to run the sink or save command 
after the analysis is over rather run the command for saving the file before 
starting to run the analysis, so the file gets saved automatically after the 
script has finished running Priya
 


On Wednesday, 1 November 2017 7:53 PM, Eric Berger  
wrote:
 

 Hi Priya,
You did not follow the logic of the pseudo-code. The sink("filename"), sink() 
pair captures whatever output is generated between the first sink statement and 
the second sink statement.You need (possibly) to do:
sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//attr. txt") net <- loadNetwork("C://Users//Priya/ 
/Desktop//Attractor analysis_all genes//synaptogenesis// regulationof_dopamine_ 
signaling_submodule3.txt")attr <- getAttractors(net, type="asynchronous")
sink()
HTH,Eric


 
On Wed, Nov 1, 2017 at 4:10 PM, Priya Arasu  wrote:

Hi Eric,I tried as you suggested but I could not find the output in the text 
file I created (attr.txt)

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ 
signaling_submodule3.txt")sink("C://Users//Priya// Desktop//Attractor 
analysis_all genes//synaptogenesis//attr. txt")


sink()

attr <- getAttractors(net, type="asynchronous")
 Priya
 

On Wednesday, 1 November 2017 6:54 PM, Eric Berger  
wrote:
 

 Some comments:1. sink() does not return a value. There is on point to set attr 
<- sink(...). Just give the command sink("C://etc")2. to complete the 
saving to the file you must give a second sink command with no argument:  
sink()So your code would be (pseudo-code, not actual code) sink( "filename" )do 
something that prints output which will be captured by sinksink() HTH,Eric


On Wed, Nov 1, 2017 at 1:32 PM, Priya Arasu via R-help  
wrote:

Hi,I want the results to be saved automatically in a output text file after the 
script has finished running.

I used the sink function in the following example, but the results file 
(output.txt) was empty.

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ signaling_submodule3.txt")# 
First I loaded theinput file for which I want to identify attractors attr <- 
sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//output. txt")# used the sink function to save the 
results from attr function

attr <- getAttractors(net, type="asynchronous")# then ran the script for 
identifying attractors Is there any function to save the results before setting 
the script to run, so that results are automatically saved in a text file after 
the script has finished running?

Thank youPriya



        [[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 to save results

2017-11-01 Thread Priya Arasu via R-help
Hi Eric,Thanks for the explanation. Is there a way to save the results 
automatically after the analysis gets over?. As I recently lost the results, 
because I didn't save the results. I don't want to run the sink or save command 
after the analysis is over rather run the command for saving the file before 
starting to run the analysis, so the file gets saved automatically after the 
script has finished running
Priya
 


On Wednesday, 1 November 2017 7:53 PM, Eric Berger  
wrote:
 

 Hi Priya,
You did not follow the logic of the pseudo-code. The sink("filename"), sink() 
pair captures whatever output is generated between the first sink statement and 
the second sink statement.You need (possibly) to do:
sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//attr. txt")
net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ signaling_submodule3.txt")attr 
<- getAttractors(net, type="asynchronous")
sink()
HTH,Eric


 
On Wed, Nov 1, 2017 at 4:10 PM, Priya Arasu  wrote:

Hi Eric,I tried as you suggested but I could not find the output in the text 
file I created (attr.txt)

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ 
signaling_submodule3.txt")sink("C://Users//Priya// Desktop//Attractor 
analysis_all genes//synaptogenesis//attr. txt")


sink()

attr <- getAttractors(net, type="asynchronous")
 Priya
 

On Wednesday, 1 November 2017 6:54 PM, Eric Berger  
wrote:
 

 Some comments:1. sink() does not return a value. There is on point to set attr 
<- sink(...). Just give the command sink("C://etc")2. to complete the 
saving to the file you must give a second sink command with no argument:  
sink()So your code would be (pseudo-code, not actual code)
sink( "filename" )do something that prints output which will be captured by 
sinksink()
HTH,Eric


On Wed, Nov 1, 2017 at 1:32 PM, Priya Arasu via R-help  
wrote:

Hi,I want the results to be saved automatically in a output text file after the 
script has finished running.

I used the sink function in the following example, but the results file 
(output.txt) was empty.

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ signaling_submodule3.txt")# 
First I loaded theinput file for which I want to identify attractors
attr <- sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//output. txt")# used the sink function to save the 
results from attr function

attr <- getAttractors(net, type="asynchronous")# then ran the script for 
identifying attractors
Is there any function to save the results before setting the script to run, so 
that results are automatically saved in a text file after the script has 
finished running?

Thank youPriya



        [[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] Function to save results

2017-11-01 Thread Priya Arasu via R-help
Hi Eric,I tried as you suggested but I could not find the output in the text 
file I created (attr.txt)

net <- loadNetwork("C://Users//Priya//Desktop//Attractor analysis_all 
genes//synaptogenesis//regulationof_dopamine_signaling_submodule3.txt")sink("C://Users//Priya//Desktop//Attractor
 analysis_all genes//synaptogenesis//attr.txt")


sink()

attr <- getAttractors(net, type="asynchronous")
 Priya
 

On Wednesday, 1 November 2017 6:54 PM, Eric Berger  
wrote:
 

 Some comments:1. sink() does not return a value. There is on point to set attr 
<- sink(...). Just give the command sink("C://etc")2. to complete the 
saving to the file you must give a second sink command with no argument:  
sink()So your code would be (pseudo-code, not actual code)
sink( "filename" )do something that prints output which will be captured by 
sinksink()
HTH,Eric


On Wed, Nov 1, 2017 at 1:32 PM, Priya Arasu via R-help  
wrote:

Hi,I want the results to be saved automatically in a output text file after the 
script has finished running.

I used the sink function in the following example, but the results file 
(output.txt) was empty.

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ signaling_submodule3.txt")# 
First I loaded theinput file for which I want to identify attractors
attr <- sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//output. txt")# used the sink function to save the 
results from attr function

attr <- getAttractors(net, type="asynchronous")# then ran the script for 
identifying attractors
Is there any function to save the results before setting the script to run, so 
that results are automatically saved in a text file after the script has 
finished running?

Thank youPriya



        [[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] Function to save results

2017-11-01 Thread Eric Berger
Hi Priya,

You did not follow the logic of the pseudo-code.
The sink("filename"), sink() pair captures whatever output is generated
between the first sink statement and the second sink statement.
You need (possibly) to do:

sink("C://Users//Priya//Desktop//Attractor analysis_all
genes//synaptogenesis//attr.txt")


net <- loadNetwork("C://Users//Priya//Desktop//Attractor analysis_all
genes//synaptogenesis//regulationof_dopamine_signaling_submodule3.txt")

attr <- getAttractors(net, type="asynchronous")


sink()


HTH,

Eric






On Wed, Nov 1, 2017 at 4:10 PM, Priya Arasu  wrote:

> Hi Eric,
> I tried as you suggested but I could not find the output in the text file
> I created (attr.txt)
>
> net <- loadNetwork("C://Users//Priya//Desktop//Attractor analysis_all 
> genes//synaptogenesis//regulationof_dopamine_signaling_submodule3.txt")
>
> sink("C://Users//Priya//Desktop//Attractor analysis_all 
> genes//synaptogenesis//attr.txt")
>
>
> sink()
>
> attr <- getAttractors(net, type="asynchronous")
>
>
> Priya
>
>
> On Wednesday, 1 November 2017 6:54 PM, Eric Berger 
> wrote:
>
>
> Some comments:
> 1. sink() does not return a value. There is on point to set attr <-
> sink(...). Just give the command sink("C://etc")
> 2. to complete the saving to the file you must give a second sink command
> with no argument:  sink()
> So your code would be (pseudo-code, not actual code)
>
> sink( "filename" )
> do something that prints output which will be captured by sink
> sink()
>
> HTH,
> Eric
>
>
>
> On Wed, Nov 1, 2017 at 1:32 PM, Priya Arasu via R-help <
> r-help@r-project.org> wrote:
>
> Hi,I want the results to be saved automatically in a output text file
> after the script has finished running.
>
> I used the sink function in the following example, but the results file
> (output.txt) was empty.
>
> net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all
> genes//synaptogenesis// regulationof_dopamine_ signaling_submodule3.txt")#
> First I loaded theinput file for which I want to identify attractors
> attr <- sink("C://Users//Priya// Desktop//Attractor analysis_all
> genes//synaptogenesis//output. txt")# used the sink function to save the
> results from attr function
>
> attr <- getAttractors(net, type="asynchronous")# then ran the script for
> identifying attractors
> Is there any function to save the results before setting the script to
> run, so that results are automatically saved in a text file after the
> script has finished running?
>
> Thank youPriya
>
>
>
> [[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] Function to save results

2017-11-01 Thread Eric Berger
Some comments:
1. sink() does not return a value. There is on point to set attr <-
sink(...). Just give the command sink("C://etc")
2. to complete the saving to the file you must give a second sink command
with no argument:  sink()
So your code would be (pseudo-code, not actual code)

sink( "filename" )
do something that prints output which will be captured by sink
sink()

HTH,
Eric



On Wed, Nov 1, 2017 at 1:32 PM, Priya Arasu via R-help  wrote:

> Hi,I want the results to be saved automatically in a output text file
> after the script has finished running.
>
> I used the sink function in the following example, but the results file
> (output.txt) was empty.
>
> net <- loadNetwork("C://Users//Priya//Desktop//Attractor analysis_all
> genes//synaptogenesis//regulationof_dopamine_signaling_submodule3.txt")#
> First I loaded theinput file for which I want to identify attractors
> attr <- sink("C://Users//Priya//Desktop//Attractor analysis_all
> genes//synaptogenesis//output.txt")# used the sink function to save the
> results from attr function
>
> attr <- getAttractors(net, type="asynchronous")# then ran the script for
> identifying attractors
> Is there any function to save the results before setting the script to
> run, so that results are automatically saved in a text file after the
> script has finished running?
>
> Thank youPriya
>
>
>
> [[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.


  1   2   3   4   5   6   7   8   9   10   >