Working code stopped working when reloading rStudio - r

I have several chunks of code that use pipes and many of them have stopped working when I reloaded rStudio that did not happen before. The following code was working before:
library(dplyr)
df <- data.frame(a = c("A", "B", "A","B" ,"A" ,"B"), b = c(1, 2, 3,4,5,6))
df %>% count(a)
but now it tells me Error in UseMethod("as.quoted") : no applicable method for 'as.quoted' applied to an object of class "function" has to be written as:
count(df$a)
or:
df %>% count(vars="a")
any ideas on what I could have done? rStudio says it's up to date, I'm using R 3.6.1 and I also tried reinstalling dplyr.
EDIT:
here is information from sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_1.4.0 lubridate_1.7.4 tidyr_1.0.0 plyr_1.8.4
[5] dplyr_0.8.3
loaded via a namespace (and not attached):
[1] Rcpp_1.0.3 rstudioapi_0.10 knitr_1.26 magrittr_1.5
[5] tidyselect_0.2.5 xtable_1.8-4 R6_2.4.1 rlang_0.4.2
[9] fastmap_1.0.1 stringr_1.4.0 tools_3.6.1 xfun_0.11
[13] htmltools_0.4.0 assertthat_0.2.1 digest_0.6.23 tibble_2.1.3
[17] lifecycle_0.1.0 crayon_1.3.4 later_1.0.0 purrr_0.3.3
[21] promises_1.1.0 vctrs_0.2.0 rsconnect_0.8.15 zeallot_0.1.0
[25] mime_0.7 glue_1.3.1 stringi_1.4.3 compiler_3.6.1
[29] pillar_1.4.2 backports_1.1.5 httpuv_1.5.2 pkgconfig_2.0.3

Related

Error in load_private_package("glue") : Cannot load glue from the private library

I'm trying to install R packages using pak R package as follows:
library(pak)
pkg_install("usethis")
However, I'm getting the following error message with all packages:
Error in load_private_package("glue") :
Cannot load glue from the private library
Session Info
sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] pak_0.2.1
loaded via a namespace (and not attached):
[1] rstudioapi_0.13 knitr_1.37.4 xml2_1.3.3
[4] magrittr_2.0.2 rvest_1.0.2 munsell_0.5.0
[7] colorspace_2.0-3 viridisLite_0.4.0 R6_2.5.1
[10] rlang_1.0.1.9000 fastmap_1.1.0 stringr_1.4.0
[13] httr_1.4.2 tools_4.1.2 webshot_0.5.2
[16] pacman_0.5.1 xfun_0.29.3 cli_3.2.0
[19] htmltools_0.5.2 systemfonts_1.0.4 digest_0.6.29
[22] lifecycle_1.0.1 kableExtra_1.3.4 purrr_0.3.4
[25] glue_1.6.1 evaluate_0.15 rmarkdown_2.11.22
[28] stringi_1.7.6 compiler_4.1.2 scales_1.1.1
[31] svglite_2.1.0
I resolved it removing pak and reinstalling it with
install.packages("pak", type = "source")

could not find function "dbconnect" in R

I am running RStudio Version 1.4.1106 and R 4.0.4. Additionally, have deleted the following packages and reinstalled them; odbc, DBI, and data.table. Next, I load them (library(odbc) and library(DBI)) and so on. However, when I run the following command, I still get the following error. What else do I need to do
Error in dbConnect(odbc::odbc(), "DB") :
could not find function "dbConnect"
sessioninfo() gives the following result
R version 4.0.4 (2021-02-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] DBI_1.1.1 odbc_1.3.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 rstudioapi_0.11 magrittr_1.5 hms_0.5.3
[5] bit_4.0.4 tidyselect_1.1.0 munsell_0.5.0 colorspace_1.4-1
[9] R6_2.4.1 rlang_0.4.8 fansi_0.4.1 blob_1.2.1
[13] dplyr_1.0.2 tools_4.0.4 grid_4.0.4 gtable_0.3.0
[17] xfun_0.19 tinytex_0.27 cli_2.1.0 ellipsis_0.3.1
[21] bit64_4.0.5 assertthat_0.2.1 tibble_3.0.4 lifecycle_0.2.0
[25] crayon_1.3.4 purrr_0.3.4 ggplot2_3.3.2 vctrs_0.3.4
[29] glue_1.4.2 compiler_4.0.4 pillar_1.4.6 generics_0.0.2
[33] scales_1.1.1 pkgconfig_2.0.3
>

data.table not reading characters appropriately

I have the following tibble:
> a
# A tibble: 1 x 1
Page
<chr>
1 勒布朗·詹姆斯_zh.wikipedia.org_desktop_all-agents
> dput(a)
structure(list(Page = "<U+52D2><U+5E03><U+6717>·<U+8A79><U+59C6><U+65AF>_zh.wikipedia.org_desktop_all-agents"), row.names = c(NA,
-1L), class = c("tbl_df", "tbl", "data.frame"))
when I convert to data.table, the encoding gets wrong:
b <- as.data.table(a)
> b
Page
1: <U+52D2><U+5E03><U+6717>·<U+8A79><U+59C6><U+65AF>_zh.wikipedia.org_desktop_all-agents
I get this dataframe from a .csv file, where these japanese characters only show correctly when I use read_csv. With fread, even if I set encoding = 'UTF-8' it doesn't work. How can I overcome this problem with data.table?
Here is my sessioninfo:
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] tibble_3.0.3 readr_1.3.1 data.table_1.13.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 rstudioapi_0.11 knitr_1.29 magrittr_1.5 hms_0.5.3 R6_2.4.1
[7] rlang_0.4.7 fansi_0.4.1 tools_4.0.2 xfun_0.16 tinytex_0.25 utf8_1.1.4
[13] cli_2.0.2 htmltools_0.5.0 ellipsis_0.3.1 yaml_2.2.1 digest_0.6.25 assertthat_0.2.1
[19] lifecycle_0.2.0 crayon_1.3.4 vctrs_0.3.2 glue_1.4.1 evaluate_0.14 rmarkdown_2.3
[25] compiler_4.0.2 pillar_1.4.6 pkgconfig_2.0.3
Update:
If I print the elemente alone, it shows correctly.
> b[[1]]
[1] "勒布朗·詹姆斯_zh.wikipedia.org_desktop_all-agents"

Error when connecting sparklyr to local

I'm trying to run sparklyr from my local environment to replicate a production environment. However, I can't even get started. I successfully installed the latest version of Spark using spark_install(), but when trying to run spark_connect() I get this vague and unhelpful error.
> library(sparklyr)
> spark_installed_versions()
spark hadoop dir
1 2.3.1 2.7 C:\\Users\\...\\AppData\\Local/spark/spark-2.3.1-bin-hadoop2.7
> spark_connect(master = "local")
Error in if (is.na(a)) return(-1L) : argument is of length zero
Here is what my session info looks like.
> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
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
other attached packages:
[1] sparklyr_0.8.4.9003
loaded via a namespace (and not attached):
[1] Rcpp_0.12.17 dbplyr_1.2.1 compiler_3.5.0 pillar_1.2.3 later_0.7.3
[6] plyr_1.8.4 bindr_0.1.1 base64enc_0.1-3 tools_3.5.0 digest_0.6.15
[11] jsonlite_1.5 tibble_1.4.2 nlme_3.1-137 lattice_0.20-35 pkgconfig_2.0.1
[16] rlang_0.2.1 psych_1.8.4 shiny_1.1.0 DBI_1.0.0 rstudioapi_0.7
[21] yaml_2.1.19 parallel_3.5.0 bindrcpp_0.2.2 stringr_1.3.1 dplyr_0.7.5
[26] httr_1.3.1 rappdirs_0.3.1 rprojroot_1.3-2 grid_3.5.0 tidyselect_0.2.4
[31] glue_1.2.0 R6_2.2.2 foreign_0.8-70 reshape2_1.4.3 purrr_0.2.5
[36] tidyr_0.8.1 magrittr_1.5 backports_1.1.2 promises_1.0.1 htmltools_0.3.6
[41] assertthat_0.2.0 mnormt_1.5-5 mime_0.5 xtable_1.8-2 httpuv_1.4.3
[46] config_0.3 stringi_1.1.7 lazyeval_0.2.1 broom_0.4.4
Well, with a bit of guessing I was able to solve my problem. I had to specify the "SPARK_HOME" environment manually.
spark_installed_versions()[1, 3] %>% spark_home_set()

R: Reduce sessionInfo output

sessionInfo() prints the below:
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 Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggmap_2.7.900 gdtools_0.1.7 bindrcpp_0.2 crosstalk_1.0.0
[5] leaflet_1.1.0 networkD3_0.4 d3heatmap_0.6.1.2 dygraphs_1.1.1.4
[9] ggiraph_0.4.2 plotly_4.7.1 ggplot2_2.2.1.9000 highcharter_0.5.0
[13] formattable_0.2.0.1 DT_0.4 kableExtra_0.7.0 stringr_1.3.0
[17] tidyr_0.8.0 dplyr_0.7.4 markdown_0.8 bookdown_0.7
[21] rmarkdown_1.9 knitr_1.20
loaded via a namespace (and not attached):
[1] nlme_3.1-131.1 bitops_1.0-6 xts_0.10-2 devtools_1.13.5
[5] lubridate_1.7.3 RColorBrewer_1.1-2 httr_1.3.1 rprojroot_1.3-2
[9] tools_3.4.3 backports_1.1.2 R6_2.2.2 lazyeval_0.2.1
[13] colorspace_1.3-2 sp_1.2-7 withr_2.1.2 mnormt_1.5-5
[17] git2r_0.21.0 curl_3.1 compiler_3.4.3 rvest_0.3.2
[21] xml2_1.2.0 officer_0.2.2 labeling_0.3 scales_0.5.0.9000
[25] psych_1.7.8 readr_1.1.1 digest_0.6.15 foreign_0.8-69
[29] R.utils_2.6.0 jpeg_0.1-8 base64enc_0.1-3 pkgconfig_2.0.1
[33] htmltools_0.3.6 maps_3.2.0 highr_0.6 rvg_0.1.8
[37] htmlwidgets_1.0 rlang_0.2.0.9001 TTR_0.23-3 quantmod_0.4-12
[41] xaringan_0.6 shiny_1.0.5 bindr_0.1.1 zoo_1.8-1
[45] jsonlite_1.5 zip_1.0.0 R.oo_1.21.0 magrittr_1.5
[49] rlist_0.4.6.1 geosphere_1.5-7 Rcpp_0.12.16 munsell_0.4.3
[53] proto_1.0.0 R.methodsS3_1.7.1 stringi_1.1.7 yaml_2.1.18
[57] plyr_1.8.4 grid_3.4.3 parallel_3.4.3 lattice_0.20-35
[61] mapproj_1.2-5 hms_0.4.2 pillar_1.2.1 igraph_1.2.1
[65] uuid_0.1-2 rjson_0.2.15 reshape2_1.4.3 glue_1.2.0
[69] evaluate_0.10.1 data.table_1.10.4-3 png_0.1-7 httpuv_1.3.6.2
[73] RgoogleMaps_1.4.1 gtable_0.2.0 purrr_0.2.4 assertthat_0.2.0
[77] xfun_0.1 mime_0.5 xtable_1.8-2 broom_0.4.3
[81] viridisLite_0.3.0 tibble_1.4.2 memoise_1.1.0
This is too much information. How can I skip the last category (loaded via a namespace (and not attached):) ?
You can remove an item from sessionInfo(), which is a list with a class attribute then use the relevant method to print the resulting object:
getS3method("print","sessionInfo")(sessionInfo()[-7])
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C LC_TIME=French_France.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.10.4 tidytext_0.1.8 bindrcpp_0.2 dplyr_0.7.4 readr_1.1.1 tidyr_0.7.2
[7] tibble_1.3.4 ggplot2_2.2.1 tidyverse_1.1.1 purrr_0.2.4 grofit_1.1.1-1 swirl_2.4.3
[13] lobstr_0.0.0.9000 Rcpp_0.12.16 rlang_0.2.0
This also works with same output:
utils:::print.sessionInfo(sessionInfo()[-7]) # thanks #r2evans
or
`class<-`(sessionInfo()[-7],"sessionInfo")
To know which part to remove from output, check:
names(sessionInfo())
[1] "R.version" "platform" "locale" "running" "basePkgs" "otherPkgs" "loadedOnly" "matprod" "BLAS"
[10] "LAPACK"
If you read ?sessionInfo, you will see that it returns an object of "sessionInfo", which is really just a named list with a lot of "stuff". Unfortunately, the only argument (package=NULL) does not limit to what you want.
When you realize that it returns a classed list, then you can start looking for print.sessionInfo, R's mechanism for class-specific function. I looked for it and didn't find it, but if you look closer into its package, you'll see utils:::print.sessionInfo. It's source is actually quite readable (not long and obfuscated).
I suggest you copy that function, remove 4 of the last 5 lines, and use it. For instance:
mySIprint <- function(x, locale = TRUE, ...) {
mkLabel <- function(L, n) {
vers <- sapply(L[[n]], function(x) x[["Version"]])
pkg <- sapply(L[[n]], function(x) x[["Package"]])
paste(pkg, vers, sep = "_")
}
# ... don't forget this code that I'm snipping out for brevity
if (!is.null(x$otherPkgs)) {
cat("\nother attached packages:\n")
print(mkLabel(x, "otherPkgs"), quote = FALSE, ...)
}
#if (!is.null(x$loadedOnly)) {
# cat("\nloaded via a namespace (and not attached):\n")
# print(mkLabel(x, "loadedOnly"), quote = FALSE, ...)
#}
invisible(x)
}
mySIprint(sessionInfo())
# R version 3.4.3 (2017-11-30)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 16299)
#
# Matrix products: default
#
# locale:
# [1] LC_COLLATE=English_United States.1252
# [2] LC_CTYPE=English_United States.1252
# [3] LC_MONETARY=English_United States.1252
# [4] LC_NUMERIC=C
# [5] LC_TIME=English_United States.1252
#
# attached base packages:
# [1] stats graphics grDevices utils datasets methods base
#
# other attached packages:
# [1] ggplot2_2.2.1 microbenchmark_1.4-4 readr_1.1.1
# [4] bindrcpp_0.2 dplyr_0.7.4 tidyr_0.7.2
# [7] testthat_2.0.0 plumber_0.4.4 r2_0.6.0

Resources