Error: cannot find function trim

Hello,

I am getting the following error in my R program running on RStudio. "Error:could not find function "trim"". This is a shiny application that calls a function that calls another program. The program has been imported into the server function with " source("Utilities/utilities.R", chdir = TRUE)". This program uses the R function trim(). I have been looking for the package of this function with not success. Could anyone tell me in what package is the function trim() found? I am not sure if that package is installed in my environment and if is not, that might be the reason why the program can not find the function trim(). When I disable the utilities.R program that contains the function trim() by commenting on source #" source("Utilities/utilities.R", chdir = TRUE)" the error keeps appearing. It seems that it does not have to do with the function trim(). This is a problem that I have encountered several times and I have been able to solve it by clearing the workspace and by restarting anew session. However, this time, that procedure does not work. Any suggestions?

There are many, many packages with a trim() function. So unfortunately, this question is almost impossible to answer without seeing your code, including the code in your utilities.R script. (If you decide to copy the code here, don't forget to make it look pretty! Helps your helpers a lot :grin:)

This next bit is a totally wild guess (since I don't have enough info to know what's going on), but in case it helps...

One reason why the error might persist after you've commented out the line that sources utilities.R is that later lines are probably still calling functions inside utilities.R (which in turn call the mysterious trim()), and those functions may still be loaded into your global environment. Have you tried commenting out the line that sources utilities.R, then clearing the workspace and restarting R? (this will almost certainly cause other errors, but the interesting question is whether you still see the error involving trim()).

1 Like

Thank you. I totally replaced the code by a copy and it seems to be fine.