Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summary and print functions #4

Closed
Prof-ThiagoOliveira opened this issue Mar 19, 2021 · 9 comments
Closed

Summary and print functions #4

Prof-ThiagoOliveira opened this issue Mar 19, 2021 · 9 comments

Comments

@Prof-ThiagoOliveira
Copy link

Prof-ThiagoOliveira commented Mar 19, 2021

Hi,

I noticed that there are no print and summary functions for each function proposed in the package. I have felt the need for print and summary functions because when, for example, we increase the number of treatments, locations and so on, and print the object, a list of two objects is automatically printed, which sometimes ends up polluting the R output, mainly, due to the "fieldBook" object in that list.

In this sense, I have worked on the following possible suggestions for you:

##' @rdname print.CRD
##' @method print CRD
##' @title Print an \code{CRD} object
##' @usage \method{print}{CRD}(x, ...)
##' @aliases print.CRD
##' @description Prints information about randomization of Completely
##'   Randomized Design (CDR)
##' @return an object inheriting from class \code{CRD}
##' @param x an object inheriting from class
##'   \code{\link[FielDHub]{CRD}}
##'
##' @param ... not used

print.CRD <- function(x, ...){
  cat("Completely Randomized Design (CRD)", "\n\n")
  cat("  Information on the design parameters:", "\n")
  str(x$infoDesign)

  cat("\n", " Head of the data frame with the CRD field book:","\n")
  head(x$fieldBook)
}


##' @rdname summary.CRD
##' @method summary CRD
##' @title Summary an \code{CRD} object
##' @usage \method{summary}{CRD}(object, ...)
##' @aliases summary.CRD
##' @description Summarise information on the design parameters and data frame structure
##' @return an object inheriting from class \code{summary.CRD}
##' @param object an object inheriting from class
##'   \code{\link[FielDHub]{CRD}}
##'
##' @param ... not used

summary.CRD <- function(object, ...) {
  structure(object, oClass=class(object),
            class = "summary.CRD")
}

##' @rdname print.summary.CRD
##' @method summary CRD
##' @title Print the summary of an \code{CRD} object
##' @usage \method{print}{summary.CRD}(object, ...)
##' @aliases print summary.CRD
##' @description Print summary information on the design parameters and data frame structure
##' @return an object inheriting from class \code{CRD}
##' @param object an object inheriting from class
##'   \code{\link[FielDHub]{CRD}}
##'
##' @param ... not used

print.summary.CRD <- function(x, ...){
  cat("Information on the design parameters:", "\n")
  str(x$infoDesign)  
  cat("\n", "Data frame structure with the CRD field book:","\n")
  str(x$fieldBook)
}

See the new output example below:

crd1 <- CRD(t = 3, 
            reps = 5, 
            plotNumber = 101, 
            seed = 1987, 
            locationName = "Fargo")
  • Print output:
print(crd1)

Completely Randomized Design (CRD) 

  Information on the design parameters: 
List of 5
 $ numberofTreatments: num 3
 $ treatments        : chr [1:3] "T1" "T2" "T3"
 $ Reps              : num 5
 $ locationName      : chr "Fargo"
 $ seed              : num 1987

Data frame head with the CRD field book: 
  ID LOCATION PLOT REP TREATMENT
1  1    Fargo  101   3        T2
2  2    Fargo  102   1        T1
3  3    Fargo  103   1        T2
4  4    Fargo  104   3        T3
5  5    Fargo  105   2        T3
6  6    Fargo  106   3        T1
  • Summary output
s1 <- summary.CRD(object)
s1

Information on the design parameters: 
List of 5
 $ numberofTreatments: num 3
 $ treatments        : chr [1:3] "T1" "T2" "T3"
 $ Reps              : num 5
 $ locationName      : chr "Fargo"
 $ seed              : num 1987

 Data frame structure with the CRD field book: 
'data.frame':	15 obs. of  5 variables:
 $ ID       : int  1 2 3 4 5 6 7 8 9 10 ...
 $ LOCATION : Factor w/ 1 level "Fargo": 1 1 1 1 1 1 1 1 1 1 ...
 $ PLOT     : int  101 102 103 104 105 106 107 108 109 110 ...
 $ REP      : int  3 4 1 3 4 1 1 4 5 2 ...
 $ TREATMENT: Factor w/ 3 levels "T1","T2","T3": 2 2 2 1 1 1 3 3 1 3 ...

I would suggest the authors consider both print and summary functions for each function related to experimental design. Clearly, feel free to modify my first suggestion, you also can add some more parameters in each function, e.g.:

print.CRD <- function(x, n=10,...){
  cat("Completely Randomized Design (CRD)", "\n\n")
  cat("  Information on the design parameters:", "\n")
  str(x$infoDesign)
  
  cat("\n", "Data frame head with the CRD field book:","\n")
  head(x$fieldBook, n=(min(n, nrow(x$fieldBook))))
}

Another alternative could be to include only a print function with the output of the summary function. Just think about it. The optimal idea is to have both functions with non overlapped outputs.

@Prof-ThiagoOliveira
Copy link
Author

I'm working on that for now, and I'll create a Pull Request when I've finished.

@DidierMurilloF
Copy link
Owner

Thanks for contributing. Thiago, do you suggest this for all functions? I can work at the same time in other functions different from that you are working. Thanks

@Prof-ThiagoOliveira
Copy link
Author

Prof-ThiagoOliveira commented Mar 19, 2021

Yes, I think it will be useful for end-users to have print and summary options for all functions. Clearly, each one's utility may vary from function to function as sometimes a summary has the same information as a print. I'll leave it up to you to update the other functions because I can spend my time reviewing another part. Ok?

@Prof-ThiagoOliveira
Copy link
Author

Please, note in the pull request I sent you, some changes in the main function were added (I added a class). I think will be good to add this part to all other functions as well.

@DidierMurilloF
Copy link
Owner

Thanks for the nice work on the CRD function. I accepted the pull. I will use those ideas for implementing your suggestions in all of rest main functions.

@Prof-ThiagoOliveira
Copy link
Author

@DidierMurilloF How are you doing with this issue? Please, if you have any questions about our discussion here, let me know. I've seen you have made several improvements in all functions. Great job!

@DidierMurilloF
Copy link
Owner

Dear Thiago, thank you for asking.

Just now I completed this issue. I adapted for each function proposed in the package the summary and print functions that you wrote. Now the end-user can call print and summary to all functions in FielDHub. Thank you so much for your contributions in all of this process. I pushed those changes. Please, let me know if you have any questions about it.

Since we finished all suggestions and changes proposed in FieDHub, we are looking forward to receiving any inquiries in the process to get FielDHub in JOSS. Thank you!

Best,

Didier Murillo

@DidierMurilloF
Copy link
Owner

Let me show you an example:

> library(FielDHub)
> # Example 1: Generates a split plot design SPD with 4 whole plots, 2 sub plots per whole plot,
> # and 4 reps in an RCBD arrangement. This in for a single location.
> SPDExample1 <- split_plot(wp = 4, sp = 2, reps = 5, l = 1, 
+                           plotNumber = 101, 
+                           seed = 14,
+                           type = 2, 
+                           locationNames = "FARGO")
> print(SPDExample1)
Split Plot Design 

Information on the design parameters: 
List of 8
 $ WholePlots    : int [1:4] 1 2 3 4
 $ SubPlots      : int [1:2] 1 2
 $ locationNumber: num 1
 $ locationNames : chr "FARGO"
 $ plotNumbers   : num 101
 $ typeDesign    : chr "RCBD"
 $ seed          : num 14
 $ idDesign      : num 5

 10 First observations of the data frame with the split_plot field book: 
   ID LOCATION PLOT REP WHOLE-PLOT SUB-PLOT TRT_COMB
1   1    FARGO  101   1          1        1      1|1
2   2    FARGO  101   1          1        2      1|2
3   3    FARGO  102   1          4        2      4|2
4   4    FARGO  102   1          4        1      4|1
5   5    FARGO  103   1          3        2      3|2
6   6    FARGO  103   1          3        1      3|1
7   7    FARGO  104   1          2        2      2|2
8   8    FARGO  104   1          2        1      2|1
9   9    FARGO  201   2          3        1      3|1
10 10    FARGO  201   2          3        2      3|2
> summary(SPDExample1)
Split Plot Design: 

1. Information on the design parameters: 
List of 8
 $ WholePlots    : int [1:4] 1 2 3 4
 $ SubPlots      : int [1:2] 1 2
 $ locationNumber: num 1
 $ locationNames : chr "FARGO"
 $ plotNumbers   : num 101
 $ typeDesign    : chr "RCBD"
 $ seed          : num 14
 $ idDesign      : num 5

2. Layout randomization for each location: 
[[1]]
      PLOT  REP Whole-plot Sub-plot
 [1,] "101" "1" "1"        "1 2"   
 [2,] "102" "1" "4"        "2 1"   
 [3,] "103" "1" "3"        "2 1"   
 [4,] "104" "1" "2"        "2 1"   
 [5,] "201" "2" "3"        "1 2"   
 [6,] "202" "2" "2"        "2 1"   
 [7,] "203" "2" "4"        "2 1"   
 [8,] "204" "2" "1"        "2 1"   
 [9,] "301" "3" "4"        "2 1"   
[10,] "302" "3" "2"        "1 2"   
[11,] "303" "3" "1"        "2 1"   
[12,] "304" "3" "3"        "2 1"   
[13,] "401" "4" "1"        "2 1"   
[14,] "402" "4" "3"        "2 1"   
[15,] "403" "4" "2"        "2 1"   
[16,] "404" "4" "4"        "1 2"   
[17,] "501" "5" "3"        "1 2"   
[18,] "502" "5" "1"        "2 1"   
[19,] "503" "5" "2"        "2 1"   
[20,] "504" "5" "4"        "2 1"   


3. Structure of the data frame with the split_plot field book: 

'data.frame':	40 obs. of  7 variables:
 $ ID        : int  1 2 3 4 5 6 7 8 9 10 ...
 $ LOCATION  : chr  "FARGO" "FARGO" "FARGO" "FARGO" ...
 $ PLOT      : num  101 101 102 102 103 103 104 104 201 201 ...
 $ REP       : int  1 1 1 1 1 1 1 1 2 2 ...
 $ WHOLE-PLOT: int  1 1 4 4 3 3 2 2 3 3 ...
 $ SUB-PLOT  : int  1 2 2 1 2 1 2 1 1 2 ...
 $ TRT_COMB  : chr  "1|1" "1|2" "4|2" "4|1" ...
> 

@Prof-ThiagoOliveira
Copy link
Author

Thanks, @DidierMurilloF. You are making excellent work/improvement in the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants