ArgumentNullException when unregistering reminder despite null check - reminders

I am using Reminders in my Orleans application, and i have a JournaledGrain that does implement the IRemindable interface. At the end of the flow i make sure i use UnregisterAsync.
The reminder gets registered with the grain's identity.The IReminder is not saved in the state but is retrieved by using the GetReminder method of the grain.
The problem:
Even though i do a null check and then unregister the reminder i still get an ArgumentNullException when calling the UnregisterAsync method.
Grain
public PaymentGrain: JournaledGrain<Something, SomethingElse>,IRemindable,IGrainWithGuidKey
{
public async Task Registering()
{
var reminder = await this.RegisterOrUpdateReminder(
this.GetPrimaryKey().ToString(),
TimeSpan.FromHours(3),
TimeSpan.FromMinutes(10));
}
//the place where the reminder is unregistering...
public async Task NotifyMerchant_PaymentNotificationSuccededAsync()
{
var reminder = await this.GetReminder(this.GetPrimaryKey().ToString());
if (reminder != null) {
await this.UnregisterReminder(reminder); //this throws with argument null
} //in the error the line 328 with thee error is here
}
}
The Exception
> warn: Orleans.Grain.InvokeException[100322]
> Exception during Grain method call of message: OneWay S10.244.0.14:11111:390542859*grn/Notification.Grains.PaymentMerchantGrain/16528479710843#d70ef3b0->S10.244.0.14:11111:390542859*grn/Notification.Grains.PaymentGrain/16528479710843#df8bf09b
> InvokeMethodRequest
> Notification.Grains.IPaymentGrain:NotifyMerchant_PaymentNotificationSuccededAsync
> #1580601:
> Exc level 0: System.ArgumentNullException: Value cannot be null. (Parameter 'reminder')
> at Orleans.Grain.UnregisterReminder(IGrainReminder reminder) in /_/src/Orleans.Core.Abstractions/Core/Grain.cs:line 152
> at Notification.Grains.PaymentGrain.NotifyMerchant_PaymentNotificationSuccededAsync(PaymentNotification_ToMerchant_SucceededMessage
> paymentSuccededDTO) in
> /src/Notification/Notification.Grains/Grain/Payment/Grains/PaymentGrain/PaymentGrain.cs:line
> 328
> at Notification.Grains.OrleansCodeGenPaymentGrainMethodInvoker.Invoke(IAddressable
> grain, InvokeMethodRequest request) in
> /src/Notification/Notification.Grains/obj/Release/net6.0/Notification.Grains.orleans.g.cs:line
> 240
> at Orleans.Runtime.GrainMethodInvoker.Invoke() in /_/src/Orleans.Runtime/Core/GrainMethodInvoker.cs:line 104
> at Orleans.Runtime.InsideRuntimeClient.Invoke(IAddressable target,
> IInvokable invokable, Message message)
> in /_/src/Orleans.Runtime/Core/InsideRuntimeClient.cs:line 469
> System.ArgumentNullException: Value cannot be null. (Parameter 'reminder')
> at Orleans.Grain.UnregisterReminder(IGrainReminder reminder) in /_/src/Orleans.Core.Abstractions/Core/Grain.cs:line 152
> at Notification.Grains.PaymentGrain.NotifyMerchant_PaymentNotificationSuccededAsync(PaymentNotification_ToMerchant_SucceededMessage
> paymentSuccededDTO) in
> /src/Notification/Notification.Grains/Grain/Payment/Grains/PaymentGrain/PaymentGrain.cs:line
> 328
> at Notification.Grains.OrleansCodeGenPaymentGrainMethodInvoker.Invoke(IAddressable
> grain, InvokeMethodRequest request) in
> /src/Notification/Notification.Grains/obj/Release/net6.0/Notification.Grains.orleans.g.cs:line
> 240
> at Orleans.Runtime.GrainMethodInvoker.Invoke() in /_/src/Orleans.Runtime/Core/GrainMethodInvoker.cs:line 104
> at Orleans.Runtime.InsideRuntimeClient.Invoke(IAddressable target,
> IInvokable invokable, Message message)
> in /_/src/Orleans.Runtime/Core/InsideRuntimeClient.cs:line 469
> 04:26: 12[WRN] {EventId={Id=100322}, SourceContext="Orleans.Grain.InvokeException",
> ActionId="8fe38a88-4767-42ea-925c-31cdcf5338f4",
> ActionName="Notification.WebApi.PaymentController.PaymentNotificationAsync
> (Notification.WebApi)", RequestId="0HMHOGFQS74L4:00000266",
> RequestPath="/payment/", ConnectionId="0HMHOGFQS74L4",
> corellationId="fe11cbbe-d9f4-48a5-9760-1a962311f40e"} Exception during
> Grain method call of message: OneWay
> S10.244.0.14:11111:390542859*grn/Notification.Grains.PaymentMerchantGrain/16528479710843#d70ef3b0->S10.244.0.14:11111:390542859*grn/Notification.Grains.PaymentGrain/16528479710843#df8bf09b
> InvokeMethodRequest
> Notification.Grains.IPaymentGrain:NotifyMerchant_PaymentNotificationSuccededAsync
> #1580601:
> Exc level 0: System.ArgumentNullException: Value cannot be null. (Parameter 'reminder')
> at Orleans.Grain.UnregisterReminder(IGrainReminder reminder) in /_/src/Orleans.Core.Abstractions/Core/Grain.cs:line 152
> at Notification.Grains.PaymentGrain.NotifyMerchant_PaymentNotificationSuccededAsync(PaymentNotification_ToMerchant_SucceededMessage
> paymentSuccededDTO) in
> /src/Notification/Notification.Grains/Grain/Payment/Grains/PaymentGrain/PaymentGrain.cs:line
> 328
> at Notification.Grains.OrleansCodeGenPaymentGrainMethodInvoker.Invoke(IAddressable
> grain, InvokeMethodRequest request) in
> /src/Notification/Notification.Grains/obj/Release/net6.0/Notification.Grains.orleans.g.cs:line
> 240
> at Orleans.Runtime.GrainMethodInvoker.Invoke() in /_/src/Orleans.Runtime/Core/GrainMethodInvoker.cs:line 104
> at Orleans.Runtime.InsideRuntimeClient.Invoke(IAddressable target, IInvokable invokable, Message message) in
> /_/src/Orleans.Runtime/Core/InsideRuntimeClient.cs:line 469
> System.ArgumentNullException: Value cannot be null. (Parameter 'reminder')
> at Orleans.Grain.UnregisterReminder(IGrainReminder reminder) in /_/src/Orleans.Core.Abstractions/Core/Grain.cs:line 152
> at Notification.Grains.PaymentGrain.NotifyMerchant_PaymentNotificationSuccededAsync(PaymentNotification_ToMerchant_SucceededMessage
> paymentSuccededDTO) in
> /src/Notification/Notification.Grains/Grain/Payment/Grains/PaymentGrain/PaymentGrain.cs:line
> 328
> at Notification.Grains.OrleansCodeGenPaymentGrainMethodInvoker.Invoke(IAddressable
> grain, InvokeMethodRequest request) in
> /src/Notification/Notification.Grains/obj/Release/net6.0/Notification.Grains.orleans.g.cs:line
> 240
> at Orleans.Runtime.GrainMethodInvoker.Invoke() in /_/src/Orleans.Runtime/Core/GrainMethodInvoker.cs:line 104
> at Orleans.Runtime.InsideRuntimeClient.Invoke(IAddressable target, IInvokable invokable, Message message) in
> /_/src/Orleans.Runtime/Core/InsideRuntimeClient.cs:line 469
> 04:26: 12[INF] {corellationId="9edd7d8c-2770-4a13-b67f-57b52e91d6d0",
> ActionId="8fe38a88-4767-42ea-925c-31cdcf5338f4",
> ActionName="Notification.WebApi.PaymentController.PaymentNotificationAsync
> (Notification.WebApi)", RequestId="0HMHOGFQS74L2:00000279",
> RequestPath="/payment/", ConnectionId="0HMHOGFQS74L2"}
> ApplyUpdatesToStorage: etag 0 special-case write Initialized event
> 04:26: 12[WRN] {EventId={Id=100322}, SourceContext="Orleans.Grain.InvokeException",
> ActionId="8fe38a88-4767-42ea-925c-31cdcf5338f4",
> ActionName="Notification.WebApi.PaymentController.PaymentNotificationAsync
> (Notification.WebApi)", RequestId="0HMHOGFQS74L4:00000266",
> RequestPath="/payment/", ConnectionId="0HMHOGFQS74L4",
> corellationId="fe11cbbe-d9f4-48a5-9760-1a962311f40e"} Exception during
> Grain method call of message: OneWay
> S10.244.0.14:11111:390542859*grn/Notification.Grains.PaymentMerchantGrain/16528479710843#d70ef3b0->S10.244.0.14:11111:390542859*grn/Notification.Grains.PaymentGrain/16528479710843#df8bf09b
> InvokeMethodRequest
> Notification.Grains.IPaymentGrain:NotifyMerchant_PaymentNotificationSuccededAsync
> #1580601:
> Exc level 0: System.ArgumentNullException: Value cannot be null. (Parameter 'reminder')
> at Orleans.Grain.UnregisterReminder(IGrainReminder reminder) in /_/src/Orleans.Core.Abstractions/Core/Grain.cs:line 152
> at Notification.Grains.PaymentGrain.NotifyMerchant_PaymentNotificationSuccededAsync(PaymentNotification_ToMerchant_SucceededMessage
> paymentSuccededDTO) in
> /src/Notification/Notification.Grains/Grain/Payment/Grains/PaymentGrain/PaymentGrain.cs:line
> 328
> at Notification.Grains.OrleansCodeGenPaymentGrainMethodInvoker.Invoke(IAddressable
> grain, InvokeMethodRequest request) in
> /src/Notification/Notification.Grains/obj/Release/net6.0/Notification.Grains.orleans.g.cs:line
> 240
> at Orleans.Runtime.GrainMethodInvoker.Invoke() in /_/src/Orleans.Runtime/Core/GrainMethodInvoker.cs:line 104
> at Orleans.Runtime.InsideRuntimeClient.Invoke(IAddressable target, IInvokable invokable, Message message) in
> /_/src/Orleans.Runtime/Core/InsideRuntimeClient.cs:line 469
> System.ArgumentNullException: Value cannot be null. (Parameter 'reminder')
> at Orleans.Grain.UnregisterReminder(IGrainReminder reminder) in /_/src/Orleans.Core.Abstractions/Core/Grain.cs:line 152
> at Notification.Grains.PaymentGrain.NotifyMerchant_PaymentNotificationSuccededAsync(PaymentNotification_ToMerchant_SucceededMessage
> paymentSuccededDTO) in
> /src/Notification/Notification.Grains/Grain/Payment/Grains/PaymentGrain/PaymentGrain.cs:line
> 328
> at Notification.Grains.OrleansCodeGenPaymentGrainMethodInvoker.Invoke(IAddressable
> grain, InvokeMethodRequest request) in
> /src/Notification/Notification.Grains/obj/Release/net6.0/Notification.Grains.orleans.g.cs:line
> 240
> at Orleans.Runtime.GrainMethodInvoker.Invoke() in /_/src/Orleans.Runtime/Core/GrainMethodInvoker.cs:line 104
> at Orleans.Runtime.InsideRuntimeClient.Invoke(IAddressable target, IInvokable invokable, Message message) in
> /_/src/Orleans.Runtime/Core/InsideRuntimeClient.cs:line 469
> 04:26: 12[INF] {corellationId="c3beb36f-699f-4644-9468-2d1b7fec05fa",
> ActionId="8fe38a88-4767-42ea-925c-31cdcf5338f4",
> ActionName="Notification.WebApi.PaymentController.PaymentNotificationAsync
> (Notification.WebApi)", RequestId="0HMHOGFQS743R:00000033",
> RequestPath="/payment/", ConnectionId="0HMHOGFQS743R"}
> ApplyUpdatesToStorage: etag 0 special-case write Initialized event
UPDATE The problem appears only during heavy load on the application ! If i send a request the flow is ok i do not get the error. When i load test i get it.
Can someone tell if there could be a problem with the reminder management or ?

Related

getting following error in R : invalid char in json text

Tried reading my JSON data(extracted from a zip file) into an R-object using following code:
myHistory <- fromJSON("Takeout/Location History/Location
History.json")
But Upon execution, getting the following error:
Error: lexical error: invalid char in json text.
Takeout/Location History/Locati
(right here) ------^
actual error pic
Kindly help
Sample data of JSON File:
> { "locations" : [ {
> "timestampMs" : "1467382628714",
> "latitudeE7" : 286423676,
> "longitudeE7" : 773812320,
> "accuracy" : 688,
> "activity" : [ {
> "timestampMs" : "1467382628569",
> "activity" : [ {
> "type" : "IN_VEHICLE",
> "confidence" : 61
> }, {
> "type" : "UNKNOWN",
> "confidence" : 20
> }, {
> "type" : "STILL",
> "confidence" : 10
> }, {
> "type" : "ON_FOOT",
> "confidence" : 5
> }, {
> "type" : "WALKING",
> "confidence" : 5
> }, {
> "type" : "ON_BICYCLE",
> "confidence" : 3
> } ]
> } ] }

R Shiny Server Segmentation Fault

I have been getting the following a Segmentation Fault on my Shiny Server running on a Linux machine:
-bash: line 1: 29254 Segmentation fault R --no-save --slave -f \/opt\/shiny-server\/R\/SockJSAdapter\.R
"
It started three days ago on an application that was previously working fine. The application does not give an error on my Windows machine. I have renewed all the packages and RStudio on the machine. I have tried to find an answer, but there is very little info about Segfaults.
I have tried to reproduce the error and stripped the code to bare minimum. I discovered that rendering text and tables (base and DataTables) is OK, but rendering any plot (base, ggplot, plotly) produces the segmentation error. The code that gives an error and the error messege from JavaScript console is below.
I also tried starting the code through a web browser from the RStudio on the Linux machine to see if I can get more info, but it just crached giving me the following error message:
Rstudio browser error message
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.4.0 tools_3.4.0
ui.R
library(shinydashboard)
dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
h4('Text'),
textOutput('TextT'),
dataTableOutput('Tabel'),
plotOutput('Plot')
)
)
server.R
server <- function(input, output, session) {
output$TextT = renderText('text text')
output$Tabel = renderDataTable(data.frame(A = 1))
output$Plot = renderPlot(plot(data.frame(x = c(1:10), y = c(11:20))))
}
JavaScript error console:
68: messageHandler(binary, msg)
69: withCallingHandlers(expr, error = function(e) { if (is.null(attr(e, "stack.trace", exact = TRUE))) { calls <- sys.calls() attr(e, "stack.trace") <- calls stop(e) }})
70: captureStackTraces(expr)
71: withCallingHandlers(captureStackTraces(expr), error = function(cond) { if (inherits(cond, "shiny.silent.error")) return() if (isTRUE(getOption("show.error.messages"))) { printError(cond, full = full, offset = offset) }})
72: withLogErrors(messageHandler(binary, msg))
73: handler(binary, message)
74: doTryCatch(return(expr), name, parentenv, handler)
75: tryCatchOne(expr, names, parentenv, handlers[[1L]])
76: tryCatchList(expr, classes, parentenv, handlers)
77: 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 = outFile) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error", condition = e))})
78: try(handler(binary, message))
79: (function (handle, binary, message) { for (handler in .wsconns[[as.character(handle)]]$.messageCallbacks) { result <- try(handler(binary, message)) if (inherits(result, "try-error")) { .wsconns[[as.character(handle)]]$close() return() } }})("60893360", FALSE, "{\"method\":\"init\",\"data\":{\"sidebarItemExpanded\":null,\"sidebarCollapsed\":false,\".clientdata_output_Plot_width\":1190,\".clientdata_output_Plot_height\":400,\".clientdata_output_TextT_hidden\":false,\".clientdata_output_Tabel_hidden\":false,\".clientdata_output_Plot_hidden\":false,\".clientdata_pixelratio\":0.8695651888847351,\".clientdata_url_protocol\":\"http:\",\".clientdata_url_hostname\":\"apps.teed.ee\",\".clientdata_url_port\":\"\",\".clientdata_url_pathname\":\"/VisualiseerimineVer2/\",\".clientdata_url_search\":\"\",\".clientdata_url_hash_initial\":\"\",\".clientdata_url_hash\":\"\",\".clientdata_singletons\":\"\",\".clientdata_allowDataUriScheme\":true}}")
80: evalq((function (handle, binary, message) { for (handler in .wsconns[[as.character(handle)]]$.messageCallbacks) { result <- try(handler(binary, message)) if (inherits(result, "try-error")) { .wsconns[[as.character(handle)]]$close() return() } }})("60893360", FALSE, "{\"method\":\"init\",\"data\":{\"sidebarItemExpanded\":null,\"sidebarCollapsed\":false,\".clientdata_output_Plot_width\":1190,\".clientdata_output_Plot_height\":400,\".clientdata_output_TextT_hidden\":false,\".clientdata_output_Tabel_hidden\":false,\".clientdata_output_Plot_hidden\":false,\".clientdata_pixelratio\":0.8695651888847351,\".clientdata_url_protocol\":\"http:\",\".clientdata_url_hostname\":\"apps.teed.ee\",\".clientdata_url_port\":\"\",\".clientdata_url_pathname\":\"/VisualiseerimineVer2/\",\".clientdata_url_search\":\"\",\".clientdata_url_hash_initial\":\"\",\".clientdata_url_hash\":\"\",\".clientdata_singletons\":\"\",\".clientdata_allowDataUriScheme\":true}}"), <environment>)
81: evalq((function (handle, binary, message) { for (handler in .wsconns[[as.character(handle)]]$.messageCallbacks) { result <- try(handler(binary, message)) if (inherits(result, "try-error")) { .wsconns[[as.character(handle)]]$close() return() } }})("60893360", FALSE, "{\"method\":\"init\",\"data\":{\"sidebarItemExpanded\":null,\"sidebarCollapsed\":false,\".clientdata_output_Plot_width\":1190,\".clientdata_output_Plot_height\":400,\".clientdata_output_TextT_hidden\":false,\".clientdata_output_Tabel_hidden\":false,\".clientdata_output_Plot_hidden\":false,\".clientdata_pixelratio\":0.8695651888847351,\".clientdata_url_protocol\":\"http:\",\".clientdata_url_hostname\":\"apps.teed.ee\",\".clientdata_url_port\":\"\",\".clientdata_url_pathname\":\"/VisualiseerimineVer2/\",\".clientdata_url_search\":\"\",\".clientdata_url_hash_initial\":\"\",\".clientdata_url_hash\":\"\",\".clientdata_singletons\":\"\",\".clientdata_allowDataUriScheme\":true}}"), <environment>)
82: doTryCatch(return(expr), name, parentenv, handler)
83: tryCatchOne(expr, names, parentenv, handlers[[1L]])
84: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
85: doTryCatch(return(expr), name, parentenv, handler)
86: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), names[nh], parentenv, handlers[[nh]])
87: tryCatchList(expr, classes, parentenv, handlers)
88: tryCatch(evalq((function (handle, binary, message) { for (handler in .wsconns[[as.character(handle)]]$.messageCallbacks) { result <- try(handler(binary, message)) if (inherits(result, "try-error")) { .wsconns[[as.character(handle)]]$close() return() } }})("60893360", FALSE, "{\"method\":\"init\",\"data\":{\"sidebarItemExpanded\":null,\"sidebarCollapsed\":false,\".clientdata_output_Plot_width\":1190,\".clientdata_output_Plot_height\":400,\".clientdata_output_TextT_hidden\":false,\".clientdata_output_Tabel_hidden\":false,\".clientdata_output_Plot_hidden\":false,\".clientdata_pixelratio\":0.8695651888847351,\".clientdata_url_protocol\":\"http:\",\".clientdata_url_hostname\":\"apps.teed.ee\",\".clientdata_url_port\":\"\",\".clientdata_url_pathname\":\"/VisualiseerimineVer2/\",\".clientdata_url_search\":\"\",\".clientdata_url_hash_initial\":\"\",\".clientdata_url_hash\":\"\",\".clientdata_singletons\":\"\",\".clientdata_allowDataUriScheme\":true}}"), <environment>), error = function (x) x, interrupt = function (x) x)
89: .Call("httpuv_run", PACKAGE = "httpuv", timeoutMillis)
90: run(timeoutMs)
91: service(timeout)
92: serviceApp()
93: withCallingHandlers(expr, error = function(e) { if (is.null(attr(e, "stack.trace", exact = TRUE))) { calls <- sys.calls() attr(e, "stack.trace") <- calls stop(e) }})
94: captureStackTraces({ scheduleFlush() while (!.globals$stopped) { serviceApp() Sys.sleep(0.001) }})
95: ..stacktraceoff..(captureStackTraces({ scheduleFlush() while (!.globals$stopped) { serviceApp() Sys.sleep(0.001) }}))
96: runApp(Sys.getenv("SHINY_APP"), port = port, launch.browser = FALSE)
An irrecoverable exception occurred. R is aborting now ...
-bash: line 1: 3049 Segmentation fault R --no-save --slave -f \/opt\/shiny-server\/R\/SockJSAdapter\.
Do you have any idea what might be behind it or how to fix it?
Thank you in advance.
PS: I am using Shiny Dashboard, but I get the same message, when I run it as a regular Shiny app
Update rJava to the latest version resolved my problem.
I was experiencing the exact same issue (shiny dashboard + rhandsontable + ggplot2).
Bárbara Borges suggested in a comment,to add options(java.parameters = "-Xss2560k") in ui.Rand that resolved my issue.

Counting number of .csv files infolder

I'm very new to R and am trying to count the number of .csv files there are in a folder. I have created the following code:
DATA <- "C:/Users/Stacey/Documents/R/Proj/RawDatabase/"
countFilesInDirectory <- function(strPathToDirectory, arrExtensions) {
intFileCount = 0;
arrFiles = scandir(strPathToDirectory);
foreach(arrFiles as strFile) {
if(is_dir("strPathToDirectory/strFile") && is_readable("strPathToDirectory/strFile")) {
intFileCount += countFilesInDirectory("strPathToDirectory/strFile", arrExtensions);
}
}
return intFileCount;
}
intFileCount = countFilesInDirectory(DATA, array('csv'));
echo intFileCount
but I get the following error output:
> DATA <- "C:/Users/Stacey/Documents/R/Proj/RawDatabase/"
>
> countFilesInDirectory <- function(strPathToDirectory, arrExtensions) {
+ intFileCount = 0;
+ arrFiles = scandir(strPathToDirectory);
+ foreach(arrFiles as strFile) {
Error: unexpected symbol in:
" arrFiles = scandir(strPathToDirectory);
foreach(arrFiles as"
>
> if(is_dir("strPathToDirectory/strFile") && is_readable("strPathToDirectory/strFile")) {
+ intFileCount += countFilesInDirectory("strPathToDirectory/strFile", arrExtensions);
Error: unexpected '=' in:
" if(is_dir("strPathToDirectory/strFile") && is_readable("strPathToDirectory/strFile")) {
intFileCount +="
> }
Error: unexpected '}' in " }"
>
> }
Error: unexpected '}' in " }"
>
> return intFileCount;
Error: unexpected symbol in " return intFileCount"
> }
Error: unexpected '}' in "}"
>
>
> intFileCount = countFilesInDirectory(DATA, array('csv'));
Error: could not find function "countFilesInDirectory"
> echo intFileCount
Error: unexpected symbol in "echo intFileCount"
Give this a shot: length(list.files("path/to/the/folder",pattern="*.csv"))
ps: no need for semi-colons at each EOL

Trace function which is declared inside another function

I have the following code:
abc <- function() {
def <- function() { }
def_enter <- function() { print("def_enter") }
def_exit <- function() { print("def_exit") }
trace(def, def_enter, exit = def_exit)
def()
}
abc_enter <- function() { print("abc_enter") }
abc_exit <- function() { print("abc_exit") }
trace(abc, abc_enter, exit = abc_exit)
abc()
I expect the output like this:
> abc()
Tracing abc() on entry
[1] "abc_enter"
Tracing def() on entry
[1] "def_enter"
Tracing def() on exit
[1] "def_exit"
Tracing abc() on exit
[1] "abc_exit"
NULL
But get such output:
> abc()
Tracing abc() on entry
[1] "abc_enter"
Tracing function "def" in package "base"
Tracing abc() on exit
[1] "abc_exit"
NULL
Is it possible to get output which I expect? How I can fix the code above?
You need to specify the environment on which the function in trace is called.
Just mention it in the argument where of trace in the definition of abc:
abc <- function() {
def <- function() { }
def_enter <- function() { print("def_enter") }
def_exit <- function() { print("def_exit") }
trace(def, def_enter, exit = def_exit, where=environment())
def()
}
And by calling abc, you will get the expected result:
#>abc()
#Tracing abc() on entry
#[1] "abc_enter"
#Tracing function "def" in package ".GlobalEnv"
#Tracing def() on entry
#[1] "def_enter"
#Tracing def() on exit
#[1] "def_exit"
#Tracing abc() on exit
#[1] "abc_exit"
#NULL

Something wrong with using for for(){} and if(){}else{}

The follwoing code just returns the results:" 0 0 " in "d:/result.txt".
I have shown the simultaneous errors that are returned below. What is wrong with my program?
for (i in 2:31)
{
if(i%%5=2)
{cat(i,1,"\n",append=TRUE,file="d:/result.txt")}
else{cat(0,0,"\n",append=TRUE,file="d:/result.txt")}
}
> for (i in 2:31)
+ {
+ if(i%%5=2){
Error: unexpected '=' in:
"{
if(i%%5="
> cat(i,1,"\n",append=TRUE,file="d:/result.txt")
Error in cat(i, 1, "\n", append = TRUE, file = "d:/result.txt") :
object 'i' not found
> }
Error: unexpected '}' in "}"
> else {
Error: unexpected 'else' in "else"
> cat(0,0,"\n",append=TRUE,file="d:/result.txt")
> }
Error: unexpected '}' in "}"
> }
Error: unexpected '}' in "}"
You need if(i%%5==2) as it's a comparison.

Resources