Ask about SMOTE in DMwR package - data-mining

I use SMOTE method by typing:
New<-SMOTE(Y~.,origin,perc.over=1300,k=5,perc.under=100)
But there is a warning:
Error in colnames<-(*tmp*, value = c("Y", "X1", "X2", "X3", "X4", :
'names' attribute [12] must be the same length as the vector [11]
I don't understand why this warning appearance. Someone help me please...

Related

CJK short title causes errors with Papaja RMarkdown

I'm writing an article with papaja package (an RMarkdown variant), which contains some Japanese characters. I would like to write its shorttitle in Japanese as follows:
title : "ここは日本語もOK: You have a Japanese title"
shorttitle : "日本語が書けません: A Japanese short title causes an error"
However, the characters cause a Pandoc's error, even though I write and save my file with UTF-8 encoding: pandoc.exe: Cannot decode byte '\x93': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream Error: pandoc document conversion failed with error 1 Execution halted. At this stage, neither tex file nor PDF was produced.
Nevertheless, when I removed the CJK characters from the short title and included other CJK ones in the main text as below, I was able to get both tex and PDF file.
title : "ここは日本語もOK: You have a Japanese title"
shorttitle : "A Japanese short title causes an error"
Then, how can I fix the problem? Or, at least, where is the cause of the promblem?
MWE
---
title : "ここは日本語もOK: You have a Japanese title"
shorttitle : "日本語が書けません: A Japanese short title causes an error"
author:
- name : "First Author"
affiliation : "1"
corresponding : yes # Define only one corresponding author
address : "Postal address"
email : "my#email.com"
affiliation:
- id : "1"
institution : "Hoge-Huga-University"
bibliography : ["r-references.bib"]
floatsintext : no
figurelist : no
tablelist : no
footnotelist : no
linenumbers : no
mask : no
draft : no
CJKmainfont: MS Mincho
#CJKsansfont: MS Gothic
documentclass : "apa6"
classoption : "doc"
output :
papaja::apa6_pdf:
number_sections: true
latex_engine: xelatex
keep_tex: true
toc: false
fig_caption: TRUE
dev: cairo_pdf
csl-hanging-indent: true
---
```{r setup, include = FALSE}
library("papaja")
r_refs("r-references.bib")
```
```{r analysis-preferences}
# Seed for random number generation
set.seed(42)
knitr::opts_chunk$set(cache.extra = knitr::rand_seed)
```
# 日本語desu・yo!
お早う
\textsf{こんにちは}
This is the \texttt{document 書類} for 資料 and I'm \textsf{stuck}...
$$
\log(5) = 1.609438
$$
# Methods
We report how we determined our sample size, all data exclusions (if any), all manipulations, and all measures in the study. <!-- 21-word solution (Simmons, Nelson & Simonsohn, 2012; retrieved from http://ssrn.com/abstract=2160588) -->
## Participants
## Material
## Procedure
## Data analysis
We used `r cite_r("r-references.bib")` for all our analyses.
# Results
# Discussion
\newpage
# References
\begingroup
\setlength{\parindent}{-0.5in}
\setlength{\leftskip}{0.5in}
<div id="refs" custom-style="Bibliography"></div>
\endgroup
Session Info
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=Japanese_Japan.932 LC_CTYPE=Japanese_Japan.932
[3] LC_MONETARY=Japanese_Japan.932 LC_NUMERIC=C
[5] LC_TIME=Japanese_Japan.932
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 compiler_4.0.2 RColorBrewer_1.1-2
[4] prettyunits_1.1.1 remotes_2.2.0 tools_4.0.2
[7] extrafont_0.17 digest_0.6.25 packrat_0.5.0
[10] pkgbuild_1.1.0 jsonlite_1.7.0 evaluate_0.14
[13] rlang_0.4.7 cli_2.0.2 rstudioapi_0.11
[16] curl_4.3 yaml_2.2.1 parallel_4.0.2
[19] xfun_0.16 Rttf2pt1_1.3.8 withr_2.2.0
[22] DiagrammeR_1.0.6.1 knitr_1.29 htmlwidgets_1.5.1
[25] rprojroot_1.3-2 glue_1.4.1 R6_2.4.1
[28] DiagrammeRsvg_0.1 processx_3.4.3 fansi_0.4.1
[31] rmarkdown_2.3 papaja_0.1.0.9997 callr_3.4.3
[34] extrafontdb_1.0 magrittr_1.5 backports_1.1.8
[37] ps_1.3.4 htmltools_0.5.0 assertthat_0.2.1
[40] rsvg_2.1 V8_3.2.0 visNetwork_2.0.9
[43] crayon_1.3.4
Pandoc version
> rmarkdown::pandoc_version()
[1] ‘2.9.2.1’

Is it possible to save Kable tables to PDF with macOS Catalina?

I use the kableExtra package all the time to create tables in R Markdown and save them to PDF. However today I upgraded to MacOS Catalina and now when I export to PDF, I cannot open the PDF image and get the error, "insufficient data for an image" in Adobe Reader. I don't get an error message in R Markdown and the PDF appears in my files, but I cannot open it in Adobe. If I use another application to open it (i.e., Preview) the resolution is very poor - and not typical of PDF. Has anyone else run into this problem and is there a solution? Many thanks for your help!
My code to retrieve the error is below:
mtcars %>%
kable() %>%
kable_styling() %>%
save_kable("test.pdf")
And session info is:
R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] metafor_2.1-0 Matrix_1.2-18 MASS_7.3-51.5 RColorBrewer_1.1-2 tidyr_1.0.2 knitr_1.28
[7] sandwich_2.5-1 plotROC_2.2.1 ggROC_1.0 pROC_1.16.1 dplyr_0.8.4 plyr_1.8.5
[13] foreign_0.8-75 gridExtra_2.3 kableExtra_1.1.0 scales_1.1.0 ggplot2_3.2.1 psych_1.9.12.31
loaded via a namespace (and not attached):
[1] Rcpp_1.0.3 lattice_0.20-38 ps_1.3.2 zoo_1.8-7 utf8_1.1.4 assertthat_0.2.1
[7] digest_0.6.24 R6_2.4.1 evaluate_0.14 httr_1.4.1 highr_0.8 pillar_1.4.3
[13] rlang_0.4.4 lazyeval_0.2.2 rstudioapi_0.11 callr_3.4.2 magick_2.3 rmarkdown_2.1
[19] labeling_0.3 webshot_0.5.2 readr_1.3.1 stringr_1.4.0 munsell_0.5.0 compiler_3.6.2
[25] xfun_0.12 pkgconfig_2.0.3 mnormt_1.5-6 htmltools_0.4.0 tidyselect_1.0.0 tibble_2.1.3
[31] fansi_0.4.1 viridisLite_0.3.0 crayon_1.3.4 withr_2.1.2 grid_3.6.2 nlme_3.1-144
[37] jsonlite_1.6.1 gtable_0.3.0 lifecycle_0.1.0 magrittr_1.5 cli_2.0.1 stringi_1.4.6
[43] farver_2.0.3 xml2_1.2.2 vctrs_0.2.2 tools_3.6.2 glue_1.3.1 purrr_0.3.3
[49] hms_0.5.3 processx_3.4.2 parallel_3.6.2 yaml_2.2.1 colorspace_1.4-1 rvest_0.3.5

flexdashboard and updateSelectInput -- won't work for the life of me

Trying to make a selectInput's range of choices depend on the value of a first selectInput.
Flexboard header looks like:
---
title: "blabla"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: embed
theme: cerulean
runtime: shiny
---
The code below, which compiles but doesn't work, is within the .sidebar chunk. I am attempting to use input$book to interactively change the range of the "chapter" selectInput. Unfortunately, updateSelectInput() seems to do nothing.
# Inputs {.sidebar data-width=150}
```{r}
selectInput("book", label = "libro", choices = c("dq1605", "dq1615"), selected="dq1605")
selectInput("chapter", label = "capítulo",choices = 0:54, selected=0)
observeEvent(input$book, {
y <- input$book
if (is.null(y)) y <- "dq1605"
chs <- if(y=="dq1605") 0:54 else 0:74
updateSelectInput(session,"chapter",choices = chs)
})
```
I have invested several hrs trying to make this work (I have used the simpler observeEvent({}) as well), but to no avail. Any suggestions?
> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.4.3 backports_1.1.2 magrittr_1.5 rsconnect_0.8.5
[5] rprojroot_1.3-2 htmltools_0.3.6 tools_3.4.3 flexdashboard_0.5.1
[9] yaml_2.1.16 Rcpp_0.12.15 stringi_1.1.6 rmarkdown_1.9
[13] knitr_1.20 jsonlite_1.5 stringr_1.2.0 digest_0.6.15
[17] evaluate_0.10.1
It works for me actually.
All I changed is the 'selected = max(chs)' to make it easier to see if it worked.
Can't see any of your packages being older than mine either.
---
title: "blabla"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: embed
theme: cerulean
runtime: shiny
---
# Inputs {.sidebar data-width=150}
```{r}
selectInput("book", label = "libro", choices = c("dq1605", "dq1615"), selected="dq1605")
selectInput("chapter", label = "capítulo",choices = 0:54, selected=0)
observeEvent(input$book, {
y <- input$book
if (is.null(y)) y <- "dq1605"
chs <- if(y=="dq1605") 0:54 else 0:74
updateSelectInput(session, "chapter", choices = chs, selected = max(chs))
})
```

R data.table and STRING_ELT() error: How to fix 'character vector' vs 'char' error?

After updating from R 3.3 to R 3.4 I have this error when using data.table package:
STRING_ELT() can only be applied to a 'character vector', not a 'char'
Has anyone experienced the same? I'm thinking about downgrading to "fix" this.
This is my session information:
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS
Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bindrcpp_0.2 purrrlyr_0.0.2 readxl_1.0.0 stringr_1.2.0
[5] bit64_0.9-7 bit_1.1-12 dtplyr_0.0.2 data.table_1.10.4
[9] dplyr_0.7.1 purrr_0.2.2.2 readr_1.1.1 tidyr_0.6.3
[13] tibble_1.3.3 ggplot2_2.2.1 tidyverse_1.1.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.11 cellranger_1.1.0 compiler_3.4.0 plyr_1.8.4 bindr_0.1
[6] forcats_0.2.0 tools_3.4.0 jsonlite_1.5 lubridate_1.6.0 nlme_3.1-131
[11] gtable_0.2.0 lattice_0.20-35 pkgconfig_2.0.1 rlang_0.1.1 psych_1.7.5
[16] parallel_3.4.0 haven_1.0.0 xml2_1.1.1 httr_1.2.1 hms_0.3
[21] grid_3.4.0 glue_1.1.1 R6_2.2.2 foreign_0.8-69 modelr_0.1.0
[26] reshape2_1.4.2 magrittr_1.5 scales_0.4.1 rvest_0.3.2 assertthat_0.2.0
[31] mnormt_1.5-5 colorspace_1.3-2 stringi_1.1.5 lazyeval_0.2.0 munsell_0.4.3
[36] broom_0.4.2
Totally stupid solution:
Uninstall everything with apt-get uninstall + apt-get autoclean.
Remove other conflicting R versions such as MRAN.
Remove all user packages directories.
Reinstall R base again.
It works !

Using the getwd() function in the output_dir parameter for rmarkdown::render (rmarkdown R package) gives unexpected result

I have this strange scenario in R where the rmarkdown::render() function is performing unexpectedly. Given the following simplistic scripts/test.Rmd
---
title: test
---
```{r test}
plot(1:10)
```
I then have the following R code:
> getwd()
[1] "/projects/test_project"
library('rmarkdown')
rmarkdown::render("scripts/test.Rmd", output_file = 'test.html', output_dir = paste( getwd(), '/', 'reports', sep = '') )
This ends up producing output here:
/projects/test_project/scripts/reports/test.html
Which is unexpected to me because:
> paste( getwd(), '/', 'reports', sep = '') )
/projects/test_project/reports
I would expected the test.html to be generated here /projects/test_project/reports/test.html. Interestingly, when I forgo the getwd() and use the path as a character string:
> render("scripts/test.Rmd", output_file = 'test.html', output_dir = "/projects/test_project/reports" )
This will generate the file in the expected location. Any ideas what is happening here?
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin14.1.0 (64-bit)
locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
attached base packages:
[1] splines grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] rmarkdown_0.4.2 scales_0.2.4 broom_0.3.5 data.table_1.9.4 gplots_2.15.0 RColorBrewer_1.1-2 reshape2_1.4.1 dplyr_0.3.0.2 ggplot2_1.0.0
[10] stringr_0.6.2 plyr_1.8.1 survival_2.37-7 xtable_1.7-4 fields_7.1 maps_2.3-9 spam_1.0-1 knitr_1.8 argparse_1.0.1
[19] proto_0.3-10 vimcom_1.0-0 setwidth_1.0-3 colorout_1.1-0
loaded via a namespace (and not attached):
[1] assertthat_0.1 bitops_1.0-6 caTools_1.17.1 chron_2.3-45 colorspace_1.2-4 DBI_0.3.1 digest_0.6.8 evaluate_0.5.5 findpython_1.0.1
[10] formatR_1.0 gdata_2.13.3 getopt_1.20.0 gtable_0.1.2 gtools_3.4.1 htmltools_0.2.6 KernSmooth_2.23-13 lazyeval_0.1.10 magrittr_1.5
[19] MASS_7.3-35 munsell_0.4.2 parallel_3.1.2 psych_1.4.8.11 Rcpp_0.11.3 rjson_0.2.15 tidyr_0.2.0 tools_3.1.2 yaml_2.1.13
I am facing the same issue and feel it might be because of a small bug in the render() function. I have raised a issue on its github page:
https://github.com/rstudio/rmarkdown/issues/416
As a workaround/hack I am using:
require(rmarkdown)
fl = render("awesome.Rmd")
file.copy(fl, getwd())
Hope that helps.