I am a novice to R, and I am learning from the Text Mining with R text. I am trying to invoke the following lines. Even though I follow the text, I still get an unpredicted error? I appreciate any help, thank you!
library(dplyr)
library(tidyr)
library(tidytext)
library(textdata)
nrc_joy <- get_sentiments("nrc") %>% filter(sentiment == "joy")
Error in menu(choices = c("Yes", "No"), title= title): menu() cannot be used non-interactively
In my case it worked well, you can share your session information mine is:
sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6
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_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] textdata_0.3.0 tidytext_0.2.2 tidyr_1.0.0 dplyr_0.8.3
loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 rstudioapi_0.10 magrittr_1.5
[4] rappdirs_0.3.1 hms_0.5.0 tidyselect_0.2.5
[7] lattice_0.20-38 R6_2.4.0 rlang_0.4.0
[10] tools_3.6.0 grid_3.6.0 janeaustenr_0.1.5
[13] assertthat_0.2.1 tibble_2.1.3 lifecycle_0.1.0
[16] crayon_1.3.4 Matrix_1.2-17 readr_1.3.1
[19] purrr_0.3.2 fs_1.3.1 vctrs_0.2.0
[22] tokenizers_0.2.1 SnowballC_0.6.0 zeallot_0.1.0
[25] glue_1.3.1 stringi_1.4.3 compiler_3.6.0
[28] pillar_1.4.1 generics_0.0.2 backports_1.1.4
[31] pkgconfig_2.0.2
Seems to work fine. Did you type the name of the object after you assigned it? It won't print or show an output unless you tell r to display the object or to print() the object. The output is a tibble and its dimension is 689 x 2.
nrc_joy <- get_sentiments("nrc") %>% filter(sentiment == "joy")
nrc_joy
Just click the up arrow next to this answer if it works for you.
Good luck.
Related
I want to install additional packages besides the default ones every time I restart my R Session.
I have tried this: options(HTTPUserAgent = sprintf("R/%s R (%s)", getRversion(), paste(getRversion(), R.version$platform, R.version$arch, R.version$os)))
install.packages(c(
'shinydashboard',
'shinyWidgets',
'rlist',
'sortable',
'tidyverse',
'XML',
'DescTools',
'plotly',
'leaflet',
'tidyquant',
'umap'
))
And this options(defaultPackages = c(getOption("defaultPackages"), "tidyquant", ...)) neither of which works. If all I want to do is to install the tidyquant package upon the R Session restart, how do I get it to work inside the Rprofile file?
I would definitely take #dirk-eddelbuettel's advice on this (XY problem), but it is possible if you add this to your .Rprofile:
.First <- function(){
utils::install.packages("tidyquant", repos="https://cran.csiro.au/")
library(tidyquant)
}
(This command is run before any packages are loaded so you need to specify the install.packages function comes from utils).
Not sure if this applies to windows; my system info:
> sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.4
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages:
[1] graphics grDevices utils datasets stats methods
[7] base
other attached packages:
[1] tidyquant_1.0.4 quantmod_0.4.20
[3] TTR_0.24.3 PerformanceAnalytics_2.0.4
[5] xts_0.12.1 zoo_1.8-10
[7] lubridate_1.8.0
loaded via a namespace (and not attached):
[1] magrittr_2.0.3 tidyselect_1.1.2 munsell_0.5.0
[4] colorspace_2.0-3 lattice_0.20-45 R6_2.5.1
[7] rlang_1.0.2 quadprog_1.5-8 fansi_1.0.3
[10] dplyr_1.0.9 httr_1.4.3 tcltk_4.1.3
[13] tools_4.1.3 grid_4.1.3 gtable_0.3.0
[16] utf8_1.2.2 DBI_1.1.2 cli_3.3.0
[19] ellipsis_0.3.2 assertthat_0.2.1 tibble_3.1.7
[22] lifecycle_1.0.1 crayon_1.5.1 purrr_0.3.4
[25] ggplot2_3.3.6 vctrs_0.4.1 curl_4.3.2
[28] Quandl_2.11.0 glue_1.6.2 compiler_4.1.3
[31] pillar_1.7.0 generics_0.1.2 scales_1.2.0
[34] jsonlite_1.8.0 pkgconfig_2.0.3
>
N.B. Choose your CRAN mirror accordingly (unless you also happen to be in Australia): https://cran.r-project.org/mirrors.html
The following code causes RStudio Desktop on my system to crash and I have no idea why. This code was running without problems about 9 months ago using older versions of R and RStudio.
library("MotIV")
library("org.Dm.eg.db")
library("MotifDb")
# Get all fly gene entrezID from within org.Dm.eg.db
entrez_fly <- keys(org.Dm.eg.db)
# Grab FBgn from org.Dm.eg.db
FBgn_entrez <- mapIds(org.Dm.eg.db, keys=entrez_fly, column="ENSEMBL", keytype="ENTREZID", multiVals="first")
# Remove non-match entries (NAs)
FBgn_entrez <- FBgn_entrez[!is.na(FBgn_entrez)]
# Also get FBgn <-> Symbol pairs
Symbol_FBgn <- mapIds(org.Dm.eg.db, keys=FBgn_entrez, column="SYMBOL", keytype="ENSEMBL", multiVals="first")
refseq_entrez <- toTable(org.Dm.egREFSEQ[entrez_fly])
# e.g. 'Hand'
Hand_motifdb <- query(MotifDb, 'ZEB1')
# #listData extracts a list of all TFBS in motifdb for this gene
Hand_motifs <- Hand_motifdb#listData
x <- motifMatch(Hand_motifs[1], as.list (MotifDb), top=10)
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats4 parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] MotifDb_1.30.0 Biostrings_2.56.0 XVector_0.28.0 org.Dm.eg.db_3.11.4 AnnotationDbi_1.50.3 Biobase_2.48.0
[7] MotIV_1.43.0 GenomicRanges_1.40.0 GenomeInfoDb_1.24.2 IRanges_2.22.2 S4Vectors_0.26.1 BiocGenerics_0.34.0
loaded via a namespace (and not attached):
[1] SummarizedExperiment_1.18.2 tinytex_0.26 tidyselect_1.1.0 xfun_0.18
[5] purrr_0.3.4 lattice_0.20-41 vctrs_0.3.4 generics_0.0.2
[9] rtracklayer_1.48.0 blob_1.2.1 XML_3.99-0.5 rlang_0.4.8
[13] pillar_1.4.6 glue_1.4.2 DBI_1.1.0 BiocParallel_1.22.0
[17] bit64_4.0.5 splitstackshape_1.4.8 matrixStats_0.57.0 GenomeInfoDbData_1.2.3
[21] lifecycle_0.2.0 plyr_1.8.6 zlibbioc_1.34.0 zip_2.1.1
[25] memoise_1.1.0 Rcpp_1.0.5 rGADEM_2.36.0 BSgenome_1.56.0
[29] seqLogo_1.54.3 DelayedArray_0.14.1 bit_4.0.4 Rsamtools_2.4.0
[33] digest_0.6.26 stringi_1.5.3 openxlsx_4.2.2 dplyr_1.0.2
[37] grid_4.0.2 tools_4.0.2 bitops_1.0-6 magrittr_1.5
[41] RCurl_1.98-1.2 tibble_3.0.4 RSQLite_2.2.1 crayon_1.3.4
[45] pkgconfig_2.0.3 ellipsis_0.3.1 Matrix_1.2-18 data.table_1.13.2
[49] rstudioapi_0.11 R6_2.4.1 GenomicAlignments_1.24.0 compiler_4.0.2
At this point, I have no idea where to find an issue. RStudio's log file does not contain complaints/issues. It just crashes.
EDIT:
The libraries can be installed with these lines:
First, Bioconductor:
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install(version = "3.11")
Then, the libraries:
BiocManager::install(c("MotIV", "org.Dm.eg.db", "MotifDb"))
EDIT 2: Tested with R (plain) and get the following error:
*** caught segfault ***
address 0x2, cause 'memory not mapped'
First time poster here. I hope I am doing it correctly. I have had the following issue for a while now and I really want to understand what is going wrong.
I am trying to plot a dashed line with ggplot.
x = c(1:405)
y = c(rep(0,135),seq(1:135),rep(135,135))
ggplot() + geom_line(aes(x, y),linetype = 2, size=1)
However, the dashed line comes out distorted. The lines are not evenly spaced. This happens both in the plot-window in R, and when I save the plot with ggsave. When I change the size of the plot-window the distortion changes, but it occurs usually around x = 100, 200 and/or 300. It is happening both in R and Rstudio. I am using a Mac have everything updated to the newest versions. When my colleague plots the same line in linux he has no issues.
Distorted dashed line
This is the sessionInfo:
R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.2
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
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.12.8 gtools_3.8.1 Rcpp_1.0.3 svMisc_1.1.0 cowplot_1.0.0 dplyr_0.8.3 zoo_1.8-6 car_3.0-5 carData_3.0-3
[10] ggplot2_3.2.1 lmerTest_3.1-1 lme4_1.1-21 Matrix_1.2-18
loaded via a namespace (and not attached):
[1] tidyselect_0.2.5 purrr_0.3.3 splines_3.6.2 haven_2.2.0 lattice_0.20-38 colorspace_1.4-1 vctrs_0.2.1 utf8_1.1.4
[9] rlang_0.4.2 nloptr_1.2.1 pillar_1.4.2 foreign_0.8-72 glue_1.3.1 withr_2.1.2 readxl_1.3.1 lifecycle_0.1.0
[17] munsell_0.5.0 gtable_0.3.0 cellranger_1.1.0 zip_2.0.4 labeling_0.3 rio_0.5.16 forcats_0.4.0 curl_4.3
[25] fansi_0.4.0 scales_1.1.0 backports_1.1.5 abind_1.4-5 farver_2.0.1 hms_0.5.2 digest_0.6.23 stringi_1.4.3
[33] openxlsx_4.1.4 numDeriv_2016.8-1.1 grid_3.6.2 cli_2.0.0 tools_3.6.2 magrittr_1.5 lazyeval_0.2.2 tibble_2.1.3
[41] crayon_1.3.4 pkgconfig_2.0.3 zeallot_0.1.0 MASS_7.3-51.4 assertthat_0.2.1 minqa_1.2.4 rstudioapi_0.10 R6_2.4.1
[49] boot_1.3-23 nlme_3.1-142 compiler_3.6.2
Does anyone know what could be the problem?
It does not explain why it is happening but using Cairographics with ggsave fixes the issue (see here) :
library(ggplot2)
library(Cairo)
x = c(1:405)
y = c(rep(0,135),seq(1:135),rep(135,135))
gg <- ggplot() + geom_line(aes(x, y),linetype = 2, size=1)
ggsave("plot.png", gg, type="cairo-png")
When I tried to close Rstudio in Mac I get the following error:
Error in as.POSIXlt(x, tz = tz(x)) :
argument "x" is missing, with no default
Have not tried to reisntall Rstudio as i am hoping can fix the issue.
this are the packages loaded in session:
library(readr)
library(dplyr)
library(lubridate)
library(ggplot2)
library(scales)
These are the objects in the global env:
> ls()
[1] "csv" "csv2" "csv3" "p"
>
Have tried base::q() and base::quit() and get the same error.
sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
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.4/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] shiny_1.0.3 scales_0.4.1 ggplot2_2.2.1 bindrcpp_0.2 dplyr_0.7.1 lubridate_1.6.0 readr_1.1.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.11 compiler_3.4.0 colourpicker_0.3 plyr_1.8.4 bindr_0.1 shinyjs_0.9.1
[7] tools_3.4.0 digest_0.6.12 jsonlite_1.5 tibble_1.3.3 gtable_0.2.0 pkgconfig_2.0.1
[13] rlang_0.1.1 rstudioapi_0.6 curl_2.7 stringr_1.2.0 knitr_1.16 htmlwidgets_0.8
[19] hms_0.3 grid_3.4.0 glue_1.1.1 R6_2.2.2 magrittr_1.5 htmltools_0.3.6
[25] assertthat_0.2.0 mime_0.5 colorspace_1.3-2 xtable_1.8-2 httpuv_1.3.3 labeling_0.3
[31] V8_1.5 stringi_1.1.5 miniUI_0.1.1 lazyeval_0.2.0 munsell_0.4.3
This could be because lubridate expects input but base::date() does not need it. Removing lubridate might solve the issue, or using base::date() instead. See this thread for a discussion on this issue.
I hope this helps!
I created a MonetDBLite database yesterday, populated it, and was accessing it with dplyr, however this morning I don't seem able to use dplyr.
Here's my connection:
statcast_db <- MonetDBLite::src_monetdblite("/Users/williampetti/statcast_database/statcast_db_Monet", create = FALSE)
And here's a simple query for the statcast_17 table:
statcast_db %>%
tbl("statcast_17") %>%
select(game_date) %>%
distinct() %>%
collect() %>%
tail(n = 1)
Yesterday, this worked fine. This morning, I get this error:
Error in UseMethod("db_query_fields") :
no applicable method for 'db_query_fields' applied to an object of class "MonetDBEmbeddedConnection"
If I use a simple dbGetQuery call, however, it works fine:
> dbGetQuery(statcast_db$con, "SELECT game_date FROM statcast_17 ORDER BY game_date DESC LIMIT 1")
game_date
1 2017-04-29
Here's my session info:
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] xml2_1.1.1 baseballr_0.3.1 RSQLite_1.0.0 pacman_0.4.1
[5] dplyr_0.5.0 purrr_0.2.2 readr_1.0.0 tidyr_0.6.0
[9] tibble_1.2 ggplot2_2.2.1 tidyverse_1.0.0 magrittr_1.5
[13] MonetDBLite_0.3.1 RMySQL_0.10.9 DBI_0.5-1
loaded via a namespace (and not attached):
[1] splines_3.3.1 lattice_0.20-33 colorspace_1.2-6
[4] htmltools_0.3.5 mgcv_1.8-12 chron_2.3-47
[7] XML_3.98-1.6 survival_2.40-1 hexbin_1.27.1
[10] foreign_0.8-66 RColorBrewer_1.1-2 plyr_1.8.4
[13] stringr_1.2.0 munsell_0.4.3 gtable_0.2.0
[16] rvest_0.3.2 XML2R_0.0.6 codetools_0.2-14
[19] latticeExtra_0.6-28 knitr_1.14 reldist_1.6-6
[22] htmlTable_1.7 Rcpp_0.12.9 acepack_1.4.1
[25] scales_0.4.1 pitchRx_1.8.2 Hmisc_4.0-0
[28] gridExtra_2.2.1 digest_0.6.11 stringi_1.1.3
[31] grid_3.3.1 tools_3.3.1 bitops_1.0-6
[34] lazyeval_0.2.0 RCurl_1.95-4.8 Formula_1.2-1
[37] cluster_2.0.4 MASS_7.3-45 Matrix_1.2-6
[40] data.table_1.9.6 lubridate_1.6.0 httr_1.2.1
[43] assertthat_0.1 R6_2.1.3 rpart_4.1-10
[46] nnet_7.3-12 nlme_3.1-128
I just replied to a similar question this morning after figuring out that the order in which you load MonetDBLite matters. I came across this question trying to figure out why it does matter. I was having the same type of Error in UseMethod problems as BillPetti. Making sure MonetDBLite loads after dplyr and dbplyr has resolved the issue for me. Here's the link to that other answer:
https://stackoverflow.com/a/53307673/3705612