I'm trying to create a pdf from an R markdown script which says this:
test <- group_by(trials, SubjID)
number <- summarise(test, nsubj=n())
sum(number$nsubj != 12)
but when I click on Knitpdf I get the following error:
error in eval(expr,envir,enclos): could not find function "group_by" Calls:
<Anonymous>...handle->withCallingHandlers->withVisible->eval->eval Execution halted
I have dplyr installed and it works when I send the information to the console but not when I press knitPDF.
You need to add below library import at top in R markdown-
library(dplyr)
Related
I am working on an R markdown notebook in an active renv in my R project directory. Before I had activated the environment, I could use the load function from base R without a problem. But since activating the environment, I get errors when I use load(file=abc.RData).
I have a code chunk as follows:
rm(list=ls())
library(haven)
library(dplyr)
library(data.table)
# Load complete (individual+network) data ---------------------------
load(file="/Volumes/caas/CADRE CLC Data Project5/Clean Data/AK-SU-NETWORKS-ROUT/eda.RData")
If I try to run the chunk, I get the following error:
Error in load(file = "/Volumes/caas/CADRE CLC Data Project5/Clean Data/AK-SU-NETWORKS-ROUT/eda.RData") :
unused argument (file = "/Volumes/caas/CADRE CLC Data Project5/Clean Data/AK-SU-NETWORKS-ROUT/eda.RData")
But if I knit the document, it compiles without a problem.
What might I be doing wrong?
It looks like all I had to do was specify that I wanted to use load from base, as:
base::load(file="/Volumes/caas/CADRE CLC Data Project5/Clean Data/AK-SU-NETWORKS-ROUT/eda.RData")
That seems to have fixed it.
I created my first R package which has three functions, to query the data in database and return the data frames based on user input. Since the data frames are large instead of printing them in console, I added View() within my function to show user the data extracted based on their input.
Code goes like this:
queryData <- function(p, q, r, s, t){
d <- DBI::dbGetQuery(conn = con, statement = "SELECT * FROM dataset" )
d <- d%>%
dplyr::filter(org == p) %>%
dplyr::filter(exp == q) %>%
dplyr::filter(dis %like% r) %>%
dplyr::filter(tis %like% s) %>%
dplyr::filter(Rx %like% t)
print(paste("No. of datasets that matched your criteria:",nrow(d)))
View(d)
}
R check was fine, I was able to install the package and run the functions. But it gave me error when I created vignette for the package.
Here is the error message:
Error: processing vignette 'package_vignette.Rmd' failed with diagnostics:
View() should not be used in examples etc
--- failed re-building 'package_vignette.Rmd'
SUMMARY: processing the following file failed:
'package_vignette.Rmd'
Error: Vignette re-building failed.
Any advice on how to fix this issue?
As the error message mentioned, View() is not made for RMarkdown, which is what the package vignettes are written in. The R Markdown cookbook suggests you can display the data just by calling the object using the built-in knitr::kable(). If it's too long you can show just the first bit by subsetting it. E.g.
knitr::kable(my_table[5,5])
will print only the first 5 rows and columns of the table. There are other packages you can use too (a brief list here), which work differently depending on the desired output format.
Alternatively, you can use paged tables to avoid scrolling:
rmarkdown::paged_table(my_table)
I have seen similar problems to this one but I have not found a solution for this specific case.
Context:
I have some excel files imported into Power BI and I need to do some analysis.
Goal:
I want to run the following code: head(my_df,3)
To achieve that I do the following:
Home -> Transform Data -> Power Query Editor opens -> Click on "my_df" -> "Run R script" -> "output <- head(my_df,3)
This results in the following error message:
DataSource.Error: ADO.NET: R script error. Error in head(raw_booking,
3) : object 'raw_booking' not found Execution halted
Details:
DataSourceKind=R
DataSourcePath=R
Message=R script error. Error in head(raw_booking, 3) : object 'raw_booking' not found Execution halted
I tried head(iris,3) and it worked!!!
What am I missing?
"Run R script" takes the input data from the last applied step in the query and stores it as dataset in the script window.
Therefore, try:
output <- head(dataset, 3)
I have an issue with the output of the functions from the package I created!
When I run a function from my package the results are visualized in a new window.
Output of my package that is impossible to copy
For information, in my code I use function "View" as usual.
There is a specif option to visualize outputs in the script bartool?
The following is the output I would like to have:
Usual R visualization
Thank you in advance,
I've created a package that contains only one function.
my_view <- function() {
df <- data.frame(x=1:5, y=11:15)
View(df)
}
After building it (ctrl + shift + b in RStudio) I've called the function and the dataframe is shown in new tab in RStudio.
What version of R and RStudio do you have? It is 3.6.3 and 1.2.5033 in my case. Could you try creating new package with only this function and check how the data is displayed?
I am trying to run an R Script in Azure ML Studio. Unfortunately, I receive the following error:
Error 0063: The following error occurred during evaluation of R script:
---------- Start of error message from R ----------
could not find function "timeSeries"
It seems strange that Azure ML cannot find the function timeSeries as the timeSeries package is installed by default. Here is the proof, you can see that timeSeries is listed.
Here is my code and the Azure diagram. The 1st R script was used to write a CSV of the installed packages (1st Picture). The code in the second R script is displayed to the right of the 2nd picture.
Thanks
The library needs to be loaded as it is an external library
library(timeSeries)
#Map 1-based optional input ports to variables
dataset1 <- maml.mapInputPort(1) #class: data.frame
HOLD <- maml.mapInputPort(2) #class: data.frame
colnames(HOLD) <- c("Dates", "Val")
Daily.TS <- timeSeries(HOLD$Val, as.Date(HOLD$Dates),
format="%Y-%m-%d")