multiple errors in R - r

I am trying to get three_d_array for dataset using R language. I have the same data description in different files so I ran my code for each file by changing the name only. The following is my code
#Sys.setenv(JAVA_HOME="C:\\Program Files\\Java\\jre7")
install.packages('lazyeval')
install.packages("xlsx")
install.packages("rJava")
options(java.parameters = "-Xmx10000m")
#options(java.parameters="-Xmx4000m")
options(java.home="C:/Program Files/Java/jre7/")
library(rJava)
library(xlsx)
raw23370 <- read.xlsx("C:\\Users\\Taqwa\\Desktop\\stations\\stations\\23370.xlsx",1)
out <- createWorkbook()
three_d_array <- array(0,dim = c(92, 6, 600))
#options(java.parameters = "-Xmx1000m")
for (i in 1:600){
candy = 1:nrow(raw23370)
B=sample(candy,nrow(raw23370) , replace=T)
a=raw23370[B,]
assign(paste0("sheet", i), createSheet(wb = out, sheetName = as.character(i)))
addDataFrame(x = a, sheet = eval(as.name(paste0("sheet", i))))
}
saveWorkbook(out, "C:\\Users\\Taqwa\\Desktop\\stations\\23370_output.xlsx")
I kept getting multiple errors after running the code for file number 20,
the following are my errors
library(rJava)
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/Taqwa/Documents/R/win-library/3.1/rJava/libs/x64/rJava.dll':
LoadLibrary failure: The specified module could not be found.
Error: package or namespace load failed for ‘rJava’
> library(xlsx)
Loading required package: rJava
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/Taqwa/Documents/R/win-library/3.1/rJava/libs/x64/rJava.dll':
LoadLibrary failure: The specified module could not be found.
Error: package ‘rJava’ could not be loaded
> raw23370 <- read.xlsx("C:\\Users\\Taqwa\\Desktop\\stations\\stations\\23370.xlsx",1)
Error: could not find function "read.xlsx"
> out <- createWorkbook()
Error: could not find function "createWorkbook"
> three_d_array <- array(0,dim = c(92, 6, 600))
> #options(java.parameters = "-Xmx1000m")
> for (i in 1:600){
+ candy = 1:nrow(raw23370)
+
+ B=sample(candy,nrow(raw23370) , replace=T)
+
+ a=raw23370[B,]
+ assign(paste0("sheet", i), createSheet(wb = out, sheetName = as.character(i)))
+ # you don't really need your three_d_array
+ addDataFrame(x = a, sheet = eval(as.name(paste0("sheet", i))))
+ }
Error in nrow(raw23370) : object 'raw23370' not found
> saveWorkbook(out, "C:\\Users\\Taqwa\\Desktop\\stations\\23370_output.xlsx")
Error: could not find function "saveWorkbook"
Could anyone provide help

Related

why can't I use the functions from prophet packages?

I'm not using CSV data. Is that will be a problem?
Every time I run this it will be shown couldn't find function "prophet" or "make_future_dataframe"
This is the data i use
resp_jakarta <- GET("https://data.covid19.go.id/public/api/prov_detail_DKI_JAKARTA.json")
status_code(resp_jakarta)
cov_jakarta_raw <- content(resp_jakarta, as = "parsed", simplifyVector = TRUE)
cov_jakarta <- cov_jakarta_raw$list_perkembangan
new_cov_jakarta <-
cov_jakarta %>%
select(-contains("DIRAWAT_OR_ISOLASI")) %>%
select(-starts_with("AKUMULASI")) %>%
rename(
kasus_baru = KASUS,
meninggal = MENINGGAL,
sembuh = SEMBUH
) %>%
mutate(
tanggal = as.POSIXct(tanggal / 1000, origin = "1970-01-01"),
tanggal = as.Date(tanggal)
)
#Forecast
install.packages("prophet")
trying URL https://cran.rstudio.com/bin/macosx/contrib/4.0/prophet_0.6.1.tgz
Content type 'application/x-gzip' length 6317112 bytes (6.0 MB)
downloaded 6.0 MB
The downloaded binary packages are in
/var/folders/bl/q861y47s7b7cnym8hzmryv0c0000gn/T//RtmpTKLo8z/downloaded_packages
library(prophet)
This happens when i run library(prophet)
Loading required package: Rcpp
Loading required package: rlang
Error: package or namespace load failed for ‘prophet’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/prophet/libs/prophet.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/prophet/libs/prophet.so, 6): Library not loaded: #rpath/libtbb.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/prophet/libs/prophet.so
Reason: image not found
date=as.Date(new_cov_jakarta$tanggal)
cases=new_cov_jakarta$kasus_baru
temp_prophet <- data.frame(date,cases)
temp_prophet <- temp_prophet %>% rename(ds = date, y = cases)
#Issues start from here
m <- prophet(temp_prophet)
And then this happens:
Error in prophet(temp_prophet) : could not find function "prophet"
future <- make_future_dataframe(m, periods = 30,freq="day")
Error in make_future_dataframe(m, periods = 30, freq = "day") : could not find function "make_future_dataframe"
tail(future)
forecast <- predict(m, future)
That's already been reported as an issue in prophet, and was suggested to install the package from source in order to fix it:
install.packages("prophet", type="source")
Also, double-check that both prophet.so and libtbb.dylib exist in your system.

Error: could not find function "interpolate.fft" (R module spectral IS installed)

My code:
library(spectral)
x <- seq(0,99)
y <- sin(x/6) + 0.5*cos(x/22)
z <- interpolate.fft(y)
RStudio says: Error in interpolate.fft(y) : could not find function "interpolate.fft"
When I try to use it as spectral::interpolate.fft(y), the error is
Error: 'interpolate.fft' is not an exported object from 'namespace:spectral'
Any help?

Not able to to convert R data frame to Spark DataFrame

When I try to convert my local dataframe in R to Spark DataFrame using:
raw.data <- as.DataFrame(sc,raw.data)
I get this error:
17/01/24 08:02:04 WARN RBackendHandler: cannot find matching method class org.apache.spark.sql.api.r.SQLUtils.getJavaSparkContext. Candidates are:
17/01/24 08:02:04 WARN RBackendHandler: getJavaSparkContext(class org.apache.spark.sql.SQLContext)
17/01/24 08:02:04 ERROR RBackendHandler: getJavaSparkContext on org.apache.spark.sql.api.r.SQLUtils failed
Error in invokeJava(isStatic = TRUE, className, methodName, ...) :
The question is similar to
sparkR on AWS: Unable to load native-hadoop library and
Don't need to use sc if you are using the latest version of Spark. I am using SparkR package having version 2.0.0 in RStudio. Please go through following code (that is used to connect R session with SparkR session):
if (nchar(Sys.getenv("SPARK_HOME")) < 1) {
Sys.setenv(SPARK_HOME = "path-to-spark home/spark-2.0.0-bin-hadoop2.7")
}
library(SparkR)
library(SparkR, lib.loc = c(file.path(Sys.getenv("SPARK_HOME"), "R","lib")))
sparkR.session(enableHiveSupport = FALSE,master = "spark://master url:7077", sparkConfig = list(spark.driver.memory = "2g"))
Following is the output of R console:
> data<-as.data.frame(iris)
> class(data)
[1] "data.frame"
> data.df<-as.DataFrame(data)
> class(data.df)
[1] "SparkDataFrame"
attr(,"package")
[1] "SparkR"
use this example code :
library(SparkR)
library(readr)
sc <- sparkR.init(appName = "data")
sqlContext <- sparkRSQL.init(sc)
old_df<-read_csv("/home/mx/data.csv")
old_df<-data.frame(old_df)
new_df <- createDataFrame( sqlContext, old_df)

Parallel computing problems

I seem to have run on a problem when trying to run a parallel computing in R
library(parallel)
library(foreach)
library(doParallel)
library(snow)
cl <- makeCluster(detectCores())
Loading required package: Rmpi
Error : .onLoad failed in loadNamespace() for 'Rmpi', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/PCCasa/Documents/R/win- library/3.2/Rmpi/libs/x64/Rmpi.dll':
LoadLibrary failure: The system is unable to find the package specified.
Error in makeMPIcluster(spec, ...) :
the `Rmpi' package is needed for MPI clusters.
registerDoParallel(cl)
Error in registerDoParallel(cl) : Object 'cl' not found
windowsproduces an error which advises to either repair or reinstall msmpi.dll. Could you kindly let me know what the best prodecure would be as to solve this issue
None, the RMPI spawn function is not implemented for Windows. Here is the excerpt of the RMPI code.
if (.Platform$OS=="windows"){
#stop("Spawning is not implemented. Please use mpiexec with Rprofile.")
workdrive <- unlist(strsplit(getwd(),":"))[1]
workdir <- unlist(strsplit(getwd(),"/"))
if (length(workdir) > 1)
workdir <-paste(workdir, collapse="\\")
else
workdir <- paste(workdir,"\\")
localhost <- Sys.getenv("COMPUTERNAME")
networkdrive <-NULL #.Call("RegQuery", as.integer(2),paste("NETWORK\\",workdrive,sep=""),
#PACKAGE="Rmpi")
remotepath <-networkdrive[which(networkdrive=="RemotePath")+1]
mapdrive <- as.logical(mapdrive && !is.null(remotepath))
arg <- c(Rscript, R.home(), workdrive, workdir, localhost, mapdrive, remotepath)
if (.Platform$r_arch == "i386")
realns <- mpi.comm.spawn(slave = system.file("Rslaves32.cmd",
package = "Rmpi"), slavearg = arg, nslaves = nslaves,
info = 0, root = root, intercomm = intercomm, quiet = quiet)
else
realns <- mpi.comm.spawn(slave = system.file("Rslaves64.cmd",
package = "Rmpi"), slavearg = arg, nslaves = nslaves,
info = 0, root = root, intercomm = intercomm, quiet = quiet)
}

Error with ggplot2 after installing new R

I wanted to install a new version of R.
I downloaded R-3.1.0.pkg and installed it.
I mved my packages from ~/Library/R/3.0 to ~/Library/R/3.1
the new R starts, but when I try to load some packages, I get an error.
This seems to be due to ggplot2. As I can load any package that doesn't depend on ggplot2.
I just reinstalled ggplot2 using install.packges(), but still no luck. R just crashes when I try to load the library.
I performed update.packages(). Is this related to how I migrated my packages?
Also, I seem to have packages in multiple places. Although I think RStudio seems to install all of them in the ~/Library/Frameworks/R.framework/Versions/3.1/Resources/library
thanks
> library(Hmisc)
Loading required package: grid
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2
*** caught segfault ***
address 0x18, cause 'memory not mapped'
Traceback:
1: dyn.load(file, DLLpath = DLLpath, ...)
2: library.dynam(lib, package, package.lib)
3: loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]])
4: namespaceImport(ns, loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]), from = package)
5: loadNamespace(package, c(which.lib.loc, lib.loc))
6: doTryCatch(return(expr), name, parentenv, handler)
7: tryCatchOne(expr, names, parentenv, handlers[[1L]])
8: tryCatchList(expr, classes, parentenv, handlers)
9: tryCatch(expr, error = function(e) { call <- conditionCall(e) if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L) dcall <- deparse(call)[1L] prefix <- paste("Error in", dcall, ": ") LONG <- 75L msg <- conditionMessage(e) sm <- strsplit(msg, "\n")[[1L]] w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b") if (w > LONG) prefix <- paste0(prefix, "\n ") } else prefix <- "Error : " msg <- paste0(prefix, conditionMessage(e), "\n") .Internal(seterrmessage(msg[1L])) if (!silent && identical(getOption("show.error.messages"), TRUE)) { cat(msg, file = stderr()) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error", condition = e))})
10: try({ ns <- loadNamespace(package, c(which.lib.loc, lib.loc)) env <- attachNamespace(ns, pos = pos, deps)})
11: library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc)
12: .getRequiredPackages2(pkgInfo, quietly = quietly)
13: library(Hmisc

Resources