R is giving error when input is expected by the user - r

So I have the following code:
data_load <- function(){
links_data <- readline(prompt= "Please specify the location of the data for links: ")
links <- read.csv(links_data, header=T, as.is=T)
nodes_data <- readline(prompt= "Please specify the location of the data for nodes: ")
nodes <- read.csv(nodes_data, header=T, as.is=T)
print("Data Loaded")
return(list(links=links, nodes=nodes))
}
data=data_load()
links=data$links
nodes=data$nodes
When I do load.all I don't encounter a problem but when I try to install and restart or clean and build or when I test/check package. I get the following:
ERROR: lazy loading failed for package ‘<package name>’
Exited with status 1.
Since there is no data available just yet. How can I solve this problem?
I am using RStudio.
Sorry if it is a bad question but I couldn't solve it.

Related

RDCOMClient Error - InterfaceSupportsErrorInfo persists after suggested fixes

Using the code below to pull a .csv file from Microsoft Outlook into R for routine data manipulation and keep getting the following error (specifically after running the results lines):
<checkErrorInfo> 80020009
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567
Error: Exception occurred.
Similar posts in Stack Overflow suggested adding sys.sleep() to fix this issue, allowing the system adequate time to search through e-mail subjects. After adding sys.sleep() with various time frames (ranging from 5-50), I'm still getting this error. Any suggestions or advice?
#Load in dataset from e-mail
outlook_app <-COMCreate("Outlook.Application")
search <- outlook_app$AdvancedSearch(
"Inbox",
"urn:schemas:httpsmail:subject = 'Outcome Information to Date'"
)
Sys.sleep(5)
results <- search$Results()
Sys.sleep(5)
for (i in 1:results$Count()) {
if(as.Date("1899-12-30")+floor(results$Item(i)$RecievedTime())
== as.Date(strptime(Sys.time(),format="%Y-%m-%d"))) {
email <- results$Item(i)
}
}
attachment_file<-tempfile()
email$Attachments(1)$SaveAsFile(attachment_file)
#Save outcome data in a dataframe
outcomedata<-read.csv(attachment_file)

Environmental variable causes loop in pkgdown::build_suite()

This is a continuation from an earlier post (Include Shiny app in R package: Transfer an input parameter) that successfully resolved my question but that led to another problem.
Basically, I am running a Shiny app as part of an R package. To do this, I have an environmental variable PKGENVIR. As can be seen in the previous post, I accomplished this using:
### runExample.R
PKGENVIR <- new.env(parent=emptyenv()) # package level envir
#' #export
runExample <- function(data) {
appDir <- system.file("shiny-examples", "myapp", package = "mypackage")
if (appDir == "") {
stop("Could not find example directory. Try re-installing `mypackage`.", call. = FALSE)
}
PKGENVIR$DATA <- data # put the data into envir
shiny::runApp(appDir, display.mode = "normal")
}
and in server.R:
### inside shiny app
data <- PACKAGE_NAME:::PKGENVIR$DATA ## read the data from envir
However, I am also trying to morph this into a pkgdown site. As a result, I run:
pkgdown::build_site()
However, this seems to create an infinite loop because the process freezes at the step:
Reading 'man/PKGENVIR.Rd'
Any ideas on how to approach this issue would be very helpful. I had been running pkgdown::build_site() before this and had not had issues. Hence, I am almost certain it is due to this new environmental variable.

Getting "<checkErrorInfo> 80020009 Error in .COM(x, name, ...) :" in R while accessing excel file

I have automated the process of accessing VBA Macros, from R, using Openxlsx and RDCOMClient packages. Below is the code:
Function:
OpenExcel_5param <- function(directory,filename, MacroName, param1, param2,
param3,param4, param5)
{
# Open a specific workbook in Excel:
data <- paste(c(directory,'/',filename,'.xlsm'), collapse = '')
xlApp <- COMCreate("Excel.Application")
xlWbk <- xlApp$Workbooks()$Open(data)
# this line of code might be necessary if you want to see your spreadsheet:
xlApp[['Visible']] <- TRUE
xlApp$Run(MacroName,param1,param2, param3, param4, param5)
# Close the workbook and quit the app:
xlWbk$Close(FALSE)
xlApp$Quit()
# Release resources:
rm(xlWbk, xlApp)
gc()
}
Code to access this function:
OpenExcel_5param(Common_folder,VBA_CodeFileName,"ConsumptionValidation.MARM",r_extracts,"1. UniqueUPC_Nielsen",10000,original_files,"MARM")
When I run the code, I get the following error:
80020009
Error in .COM(x, name, ...) :
When I ran the code for the first time, it worked fine. From second time onward, it started giving me this error. Same code is working just fine on a different computer. On a third computer, it works fine if I keep the excel file open, but on my computer not working at all. I have tried different version of R, but did not help.

send2cy doesn't work in Rstudio ~ Cyrest, Cyotoscape

When I run "send2cy" function in R studio, I got error.
# Basic setup
library(igraph)
library(RJSONIO)
library(httr)
dir <- "/currentdir/"
setwd(dir)
port.number = 1234
base.url = paste("http://localhost:", toString(port.number), "/v1", sep="")
print(base.url)
# Load list of edges as Data Frame
network.df <- read.table("./data/eco_EM+TCA.txt")
# Convert it into igraph object
network <- graph.data.frame(network.df,directed=T)
# Remove duplicate edges & loops
g.tca <- simplify(network, remove.multiple=T, remove.loops=T)
# Name it
g.tca$name = "Ecoli TCA Cycle"
# This function will be published as a part of utility package, but not ready yet.
source('./utility/cytoscape_util.R')
# Convert it into Cytosccape.js JSON
cygraph <- toCytoscape(g.tca)
send2cy(cygraph, 'default%20black', 'circular')
Error in file(con, "r") : cannot open the connection
Called from: file(con, "r")
But I didn't find error when I use "send2cy" function from terminal R (Run R from terminal just calling by "R").
Any advice is welcome.
I tested your script with local copies of the network data and utility script, and with updated file paths. The script ran fine for me in R Studio.
Given the error message you are seeing "Error in file..." I suspect the issue is with your local files and file paths... somehow in an R Studio-specific way?
FYI: an updated, consolidated and update set of R scripts for Cytoscape are available here: https://github.com/cytoscape/cytoscape-automation/tree/master/for-scripters/R. I don't think anything has significantly changed, but perhaps trying in a new context will resolve the issue you are facing.

Overcoming "Error: unexpected input" in RCurl

I am trying and failing to use RCurl to automate the process of fetching a spreadsheet from a web site, China Labour Bulletin's Strike Map.
Here is the URL for the spreadsheet with the options set as I'd like them:
http://strikemap.clb.org.hk/strikes/api.v4/export?FromYear=2011&FromMonth=1&ToYear=2015&ToMonth=6&_lang=en
Here is the code I'm using:
library(RCurl)
temp <- tempfile()
temp <- getForm("http://strikemap.clb.org.hk/strikes/api.v4/export",
FromYear="2011", FromMonth="1",
ToYear="2015", ToMonth="6",
_lang="en")
And here is the error message I get in response:
Error: unexpected input in:
" ToYear=2015, ToMonth=6,
_"
Any suggestions on how to get this to work?
Try enclosing _lang with a backtick.
temp <- getForm("http://strikemap.clb.org.hk/strikes/api.v4/export",
FromYear="2011",
FromMonth="1",
ToYear="2015",
ToMonth="6",
`_lang`="en")
I think R has trouble on the argument starting with an underscore. This seems to have worked for me.

Resources