I'm trying to use the bind_rows() function from dplyr (ver 0.4.1), but R command line can't find the function. It can find the help for the function, but any efforts to use the function are met with
> bind_rows()
Error: could not find function "bind_rows"
Am I doing something wrong? I understand bind_rows() was only introduced in ver 0.4.0, but I have a newer version than that.
Here is my sessionInfo()
> R version 3.1.1 (2014-07-10)
> Platform: x86_64-apple-darwin13.1.0 (64-bit)
>
> 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] utils datasets graphics grDevices stats methods base
>
> other attached packages:
> [1] lubridate_1.3.3 tidyr_0.2.0 dplyr_0.4.1 swirl_2.2.16 mvoutlier_2.0.5 sgeostat_1.0-25
>
>loaded via a namespace (and not attached):
> [1] assertthat_0.1 colorspace_1.2-4 DEoptimR_1.0-1 digest_0.6.4 GGally_0.4.8
> [6] ggplot2_1.0.0 grid_3.1.1 gtable_0.1.2 httr_0.5 magrittr_1.0.1
>[11] MASS_7.3-34 memoise_0.2.1 munsell_0.4.2 mvtnorm_1.0-0 parallel_3.1.1
>[16] pcaPP_1.9-49 pls_2.4-3 plyr_1.8.1 proto_0.3-10 Rcpp_0.11.2
>[21] RCurl_1.95-4.3 reshape_0.8.5 reshape2_1.4 robCompositions_1.9.0 robustbase_0.91-1
>[26] rrcov_1.3-4 scales_0.2.4 stats4_3.1.1 stringr_0.6.2 tcltk_3.1.1
>[31] testthat_0.8.1 tools_3.1.1 yaml_2.1.13
Did you try to call it with the package prefix, e.g.
dplyr::bind_rows()
This should work even if there is a conflict with one of the other packages.
Closing all R sessions and re-installing dplyr worked in this situation. Thanks to David Arenburg for the prompt.
Related
I'am trying to use package RODBCto access a mdb-file.
The mdb-file is created with ESRI GIS.
I want to change some entries in the attribute table.
If i try
sqlQuery(channnel = rddall, "SELECT* FROM abt_F;")
sqlFetch(channel=rddall,"txt_L ")
R crashes.
Screenshot
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=German_Austria.1252 LC_CTYPE=German_Austria.1252 LC_MONETARY=German_Austria.1252
[4] LC_NUMERIC=C LC_TIME=German_Austria.1252
attached base packages:
[1] splines grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] RODBC_1.3-12 brew_1.0-6 Hmisc_3.15-0 ggplot2_1.0.0 Formula_1.2-1 survival_2.37-7
[7] lattice_0.20-29 rgdal_1.1-8 sp_1.2-2
loaded via a namespace (and not attached):
[1] acepack_1.3-3.3 cluster_1.15.3 colorspace_1.2-5 digest_0.6.8 foreign_0.8-61
[6] gtable_0.1.2 latticeExtra_0.6-26 MASS_7.3-35 munsell_0.4.2 nnet_7.3-8
[11] plyr_1.8.3 proto_0.3-10 RColorBrewer_1.1-2 Rcpp_0.11.5 reshape2_1.4.1
[16] rpart_4.1-10 scales_0.2.4 stringr_0.6.2 tcltk_3.1.2 tools_3.1.2
Likely too late, but I just came across this question after encountering a similar problem. R was crashing for me when I tried to sqlFetch a table directly from my ArcGIS-created .mdb, and when I tried to fetch the table via a different non-GIS .mdb (I added the table to that database as an External Linked table, from the GIS .mdb). I finally got R to load the table correctly when I created a query in my non-GIS .mdb that basically replicated the initial table (although I dropped some of the unneeded columns in that query). Now, I just left the query as-is in my non-GIS .mdb, and sqlFetch the query, and it's working fine. Not really an R solution, but a potential workaround that may work for some folks.
I have a ggplot2 plotting function as part of my code.
The function works fine when the file is sourced as R code, however when I include this function in an R package (and of course I include ggplot2 and scales both in the DESCRIPTION and in the NAMESPACE files of the package) I am getting the following error:
Error in initFields(scales = scales) :
could not find function "initRefFields"
The respective call of scales in the ggplot2 object is the following:
+ facet_wrap(~PV_Type, ncol = 1, scales = "free") +
I run the latest R (3.2.0) and the latest ggplot2 (1.0.1) installed from source.
A possible solution/explanation will be highly appreciated!
EDIT: The output of sessionInfo() is the following:
R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.3 (Yosemite)
locale:
[1] C/UTF-8/C/C/C/C
attached base packages:
[1] stats graphics grDevices utils datasets base
other attached packages:
[1] argparse_1.0.1 proto_0.3-10 greater_1.0
loaded via a namespace (and not attached):
[1] Rcpp_0.11.6 DEoptimR_1.0-2 RColorBrewer_1.1-2 plyr_1.8.2
[5] methods_3.2.0 class_7.3-12 prabclus_2.2-6 tools_3.2.0
[9] digest_0.6.8 mclust_5.0.1 gtable_0.1.2 lattice_0.20-31
[13] mvtnorm_1.0-2 findpython_1.0.1 gridExtra_0.9.1 trimcluster_0.1-2
[17] stringr_1.0.0 cluster_2.0.1 RGraphics_2.0-12 fpc_2.1-9
[21] stats4_3.2.0 diptest_0.75-6 grid_3.2.0 nnet_7.3-9
[25] getopt_1.20.0 robustbase_0.92-3 flexmix_2.3-13 pander_0.5.1
[29] ggplot2_1.0.1 reshape2_1.4.1 kernlab_0.9-20 magrittr_1.5
[33] scales_0.2.4 modeltools_0.2-21 MASS_7.3-40 colorspace_1.2-6
[37] stringi_0.4-1 munsell_0.4.2 rjson_0.2.15
The .libPaths() is also rather common for my installation:
>.libPaths()
[1] "/Library/Frameworks/R.framework/Versions/3.2/Resources/library"
Perhaps I should also add that I call the function which requires the scales package from a command line R script.
(This is not a duplicate of ggplot2 Error in initFields as I tried all their recommendations (apart from reverting back to R 2.14 of course) and none worked).
I think I have found a solution/workaround.
As I noticed from sessionInfo() the methods package was not attached but rather loaded in the namespace. Therefore after attaching methods (as well as grid which was needed for a consequent function) my script work fine by oading the functions from the package.
My working sessionInfo() looks like this now:
R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.3 (Yosemite)
locale:
[1] C/UTF-8/C/C/C/C
attached base packages:
[1] grid methods stats graphics grDevices utils datasets
[8] base
other attached packages:
[1] argparse_1.0.1 proto_0.3-10 greater_1.0
loaded via a namespace (and not attached):
[1] Rcpp_0.11.6 DEoptimR_1.0-2 RColorBrewer_1.1-2 plyr_1.8.2
[5] class_7.3-12 prabclus_2.2-6 tools_3.2.0 digest_0.6.8
[9] mclust_5.0.1 gtable_0.1.2 lattice_0.20-31 mvtnorm_1.0-2
[13] findpython_1.0.1 gridExtra_0.9.1 trimcluster_0.1-2 stringr_1.0.0
[17] cluster_2.0.1 RGraphics_2.0-12 fpc_2.1-9 stats4_3.2.0
[21] diptest_0.75-6 nnet_7.3-9 getopt_1.20.0 robustbase_0.92-3
[25] flexmix_2.3-13 pander_0.5.1 ggplot2_1.0.1 reshape2_1.4.1
[29] kernlab_0.9-20 magrittr_1.5 scales_0.2.4 modeltools_0.2-21
[33] MASS_7.3-40 colorspace_1.2-6 stringi_0.4-1 munsell_0.4.2
[37] rjson_0.2.15
Thanks very much for the contribution, however I would appreciate an explanation on firstly why there is the need to explicitly attach these two packages (methods and grid) when the functions are loaded as a package, and it is not required when the function are sourced by source().
For some reason, a code I usually run in Rstudios is no longer working. I'm hoping that someone has had a similar experience and understands what's going on.
getReturns(c('C','BAC'), start='2004-01-01', end='2008-12-31')
This results in:
Error in unclass(e1) + unclass(e2) :
non-numeric argument to binary operator
I can't find anything online nor on stackoverflow that addresses this issue. Also, I saw that the most recent documentation, from July 2014 doesn't mention anything either:
http://cran.r-project.org/web/packages/stockPortfolio/stockPortfolio.pdf
Does anyone have any idea what's going on here?
It's probably a function name clash issue. Running
timeSeries::getReturns(c('C','BAC'), start='2004-01-01', end='2008-12-31')
gives me the error, but running
stockPortfolio::getReturns(c('C','BAC'), start='2004-01-01', end='2008-12-31')
works fine.
How did this happen?
You must have loaded the stockPortfolio package, and then loaded either timeSeries or another package that depends upon timeSeries. Have a look through your console for a message that looks like
The following object is masked from ‘package:stockPortfolio’:
getReturns
Use the double colon operator (as shown above) to explicitly tell R which package to look in.
I have a similar problem using stockPortfolio in a R Markdown program.
Code that works in a R file does not work in the rmd file.
```{r p3}
recordState()
ff <- allFunds1$Fund
returns <-stockPortfolio::getReturns(ff,freq="month")
save(allFunds1,file='allFunds1.rda')
```
gives the error message and traceback
Error in unclass(e1) + unclass(e2) : non-numeric argument to binary operator
5. structure(unclass(e1) + unclass(e2), class = "Date")
4.`+.Date`(as.Date(origin, ...), x)
3. as.Date.numeric(uDates, origin = minDate)
2. as.Date(uDates, origin = minDate
1. stockPortfolio::getReturns(ff, freq = "month")
My recordState function saves the results of search() and sessionInfo() in the chunk:
[1] "search:"
[1] ".GlobalEnv" "tools:rstudio" "package:stats"
[4] "package:graphics" "package:grDevices" "package:utils"
[7] "package:datasets" "package:methods" "Autoloads"
[10] "package:base"
[1] "sessionInfo():"
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X Yosemite 10.10.5
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
loaded via a namespace (and not attached):
[1] Rcpp_0.12.9 digest_0.6.11 dplyr_0.5.0
[4] rprojroot_1.2 assertthat_0.1 R6_2.2.0
[7] xtable_1.8-2 DBI_0.5-1 backports_1.0.5
[10] magrittr_1.5 evaluate_0.10 stringi_1.1.2
[13] stockPortfolio_1.2 rmarkdown_1.3 tools_3.3.2
[16] stringr_1.1.0 readr_1.0.0 yaml_2.1.14
[19] htmltools_0.3.5 knitr_1.15.1 tibble_1.2
The original posting suggests that this error can result from confusing stockPortfolio::getReturns with the function in timeSeries but I have used the full name and do not have either of the libraries loaded.
I am trying to generate a proper dendrogram in R with ggplot2 (more specifically ggdendro::ggdendrogram) because I would like to share it over plotly with my collaborators and currently I do not think it is possible with the api to generate a dendrogram with plotly.
I am mainly having troubles with the "axis" labeling when I rotate the dendrogram:
require(ggplot2)
require(ggdendro)
hc<-hclust(dist(iris[,1:4]),method="ward.D2")
ggd<-ggdendrogram(hc,rotate=TRUE)
ggd+scale_y_reverse()
This results in the following plot, where the tick labels are on the wrong side:
I would like to obtain a similar result as from R base graphics when executing plot(as.dendrogram(hc),horiz=TRUE)
As a bonus, I would like to be able to color the leaf (tick) labels separately as well as draw rect.hclust-like boxes, but this is not strictly necessary. I do know my way a little bit around ggplot2 syntax so no need to explain every possible solution in great length.
If relevant please find my sessionInfo() below, I am using R through Rstudio server on an Ubuntu 12.04 LTS server:
sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C LC_PAPER=C
[8] LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggdendro_0.1-14 cluster_1.15.2 plotly_0.4 RJSONIO_1.2-0.2 RCurl_1.95-4.1 bitops_1.0-6 devtools_1.5
[8] extrafont_0.16 RColorBrewer_1.0-5 scales_0.2.4 vegan_2.0-10 lattice_0.20-29 permute_0.8-3 splitstackshape_1.2.0
[15] data.table_1.9.2 BurStMisc_1.00 reshape2_1.4 xlsx_0.5.5 xlsxjars_0.6.0 rJava_0.9-6 ggplot2_0.9.3.1
[22] plyr_1.8.1
loaded via a namespace (and not attached):
[1] MASS_7.3-32 Rcpp_0.11.1 Rttf2pt1_1.3 colorspace_1.2-4 digest_0.6.4 evaluate_0.5.5 extrafontdb_1.0 formatR_0.10 grid_3.1.0
[10] gtable_0.1.2 httr_0.3 knitr_1.6 labeling_0.2 memoise_0.2.1 munsell_0.4.2 parallel_3.1.0 proto_0.3-10 stringr_0.6.2
[19] tools_3.1.0 whisker_0.3-2
If I include \usepackage{Sweavel} in my .rnw file, I get an X11 popup error "It seems you are using the Sweave-specific syntax; you may need Sweave2knitr("IPT-baseline-test.rnw") to convert it to knitr" when I compile in RStudio (Version 0.98.484). The document compiles, but I have to dismiss the error.
(1) Any ideas why \usepackage{Sweavel} triggers the error?
(2) Is there a way to turn off the popup since the document compiles anyway?
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
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] knitr_1.5
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 dichromat_2.0-0 digest_0.6.3 evaluate_0.5.1
[5] formatR_0.10 ggplot2_0.9.3.1 grid_3.0.2 gtable_0.1.2
[9] labeling_0.2 MASS_7.3-29 munsell_0.4.2 plyr_1.8
[13] proto_0.3-10 RColorBrewer_1.0-5 reshape2_1.2.2 scales_0.2.3
[17] stringr_0.6.2 tools_3.0.2
You shouldn't need to \usepackage{Sweavel} explicitly, I think -- knitr should handle that automatically. If you really want to suppress this false positive , you can rename Sweavel.sty to a file name that doesn't start with Sweave ... the which_sweave() function at https://github.com/yihui/knitr/blob/de7c65c58acfb1f3f5c0ac2f00b92cd2546be943/R/utils-sweave.R shows you what patterns knitr is looking for to detect "old Sweave syntax", specifically in this case the regular expression
regexp <-
'^\\s*\\\\(usepackage(\\[.*\\])?\\{Sweave|SweaveInput\\{|SweaveOpts\\{)'
So changing to mySweavel.sty should work ...
grepl(regexp,"\\usepackage{Sweave}") ## TRUE
grepl(regexp,"\\usepackage{Sweavel}") ## TRUE
grepl(regexp,"\\usepackage{mySweavel}") ## FALSE
My guess is that you have a newer version of knitr on your new than on your old machine, and it's trying harder to detect old Sweave syntax.
Removing the Sweave tag in the latex document prevented the warnings. It did not prevent the rendering of the file. Thus, the suggestion made in one of the comments above worked... knit2pdf (in my case) figures it out. - E