why is dirname(sys.frame(1)$ofile) not working anymore - r

I have used
dirname(sys.frame(1)$ofile)
to get the directory of the script I am currently running
It worked perfectly until recently where it returns an error message
Error in sys.frame(1) : not that many frames on the stack
I have my code and data in Dropbox, and since I run it on various computers where dropbox is located differently, I want to be able to know where the script running is located.
Any idea why dirname(sys.frame(1)$ofile) does not work anymore, and how to get a solution.
There is a lot having the same problem as I, but the solutions either dont work or suggest another way which does not fit.

Related

R 3.6 Shiny problem "Static path must not have trailing slash."

I just installed on my machine R 3.6 and tried to run my Shiny app and all of a sudden I get this error message:
Listening on http://10.81.197.170:1234
Error in makeTcpServer(host, port, private$appWrapper$onHeaders, private$appWrapper$onBodyData, :
Static path must not have trailing slash.
I tried to check what explained here Host shiny app on Windows but I do only have one single IP address.
I'm a very basic R user so I have no idea of what I could do to fix this problem. I also see another person had a similar issue a couple of months ago https://community.rstudio.com/t/error-using-a-shiny-app-on-windows-maketcpserver/64841 but he didn't get any answers.
Thanks for the help
This is difficult to answer specifically without seeing the code of your app.
However, I ran across the same error recently and will share what I did wrong and the fix, in case someone else got the error for the same reason I did.
In my app, I wanted to access data stored in a different folder from www, and to do this I had to add a resource path:
addResourcePath("myfolder","/foldername/")
data <- readxl::read_xlsx("myfolder/mydata.xlsx", sheet=1)
This worked when running the script locally, but not when it happened to be on a flash drive. That's when I got the error you describe above.
I also got it when using an absolute location for that folder:
addResourcePath("myfolder","E:/foldername/")
The fix was simple: remove the trailing backslash.
addResourcePath("myfolder","E:/foldername")
This may not be exactly your situation, but I'd look out for any instances where you're specifying directories to start out with.

How do I recover an R script?

I was running an R script code in Rstudio and suddenly my computer power had been lost. Now, I open the script and I can't find anything in my script except red dots (see the below figure).
I know that a similar question has been asked here. However, the answers don't work for me. How can I recover my running code?
There is a file in my directory C:\Users\Mohammad Nabati\AppData\Local\RStudio-Desktop named history_database.1 that I found the history of running.

Shiny app working locally but not deployed on shinyapps.io

I'm in a difficult situation to figure out how to publish shiny app online.
Can't find any solution in the older questions.
The app works locally perfect but its impossible to put it online.
when I run the log, show just this:
Error in serverInfo(server) : server named 'rpubs.com' does not exist
on the part
"Markers": Line 14 - Paths should be to files within the project
directory. Error in sheets_fun(path) : Evaluation error:
path[1]="database.xls".
The file *.xlsx is already in the same folder of the *rmd.
Could any one help me I have no idea how to solve this issue. I'm now in two weeks trying to solve this.
that is to grab a job, and I will appreciate a lot if anyone tell me how to make it works

Is it possible to have the entire contents of a class that tripped an error included in the stacktrace?

A lot of time can pass between the moment a stack trace is generated and the moment the stack trace is thoroughly investigated. During that time, a lot can happen to the file in question, sometimes obscuring the original error. The error might have been fixed in the meantime (overlapping bugs).
Is it possible to get Stacktraces that show the offending file at the time of the error?
Not elegantly, and you normally don't want the user browsing through code that's throwing unexpected exceptions anyway (open door to an attacker).
Usually, what happens in a dev shop is that the user reports an error, stack trace, and the build it occurred on. As a tester, you can grab that build from your archives (you ARE keeping an archive of all supported releases somewhere handy, RIGHT?), install, run, and try to reproduce the error, working with the user to provide additional info as necessary. I've seen very few bugs that couldn't be reproduced EVENTUALLY, even if it required running the program against a backup of the user's production database to do it.
As a developer, you can download that build's source code from your version control repository (you ARE using version control, RIGHT?), and examine the lines in the stack trace to try to discover the problem by inspection, and/or build and run it to reproduce the error. Then, you go back to the latest source version, build, and run the same steps (a UI automation system can help out here), and if you don't get the error, someone else already found and fixed it. If you still get the error, you also got an updated stack trace with lines that match the current build, allowing you to set your breakpoints and step through.
What KeithS said, plus there are ways to capture more helpful state information at the time of the Exception using the Exception.Data property. See http://blog.abodit.com/2010/03/using-exception-data-to-add-additional-information-to-an-exception/
While KeithS' answer as pretty much correct, it can be easier and more elegant than you think. If you can collect a dumpfile (instead of just a stack trace), you can use a Symbol Server and Source Server in combination with your debugger to automatically pull your correct-version code from source control.
For example: if you enable PDB output and source-server integration in MSBuild, and upload the resulting PDBs to a symbol server, Visual Studio can automatically load the correct source control from a TFS or SourceSafe repository based on the information in a minidump.

How do I get wkhtmltopdf running for a Drupal site on cPanel shared hosting?

First off, I will acknowledge that I am aware of another similar thread on the topic of wkhtmltopdf, but it was not similar enough to resolve my issue. Here's the other thread: wkhtmltopdf
Second, I will say that I have successfully used wkhtmltopdf with a Drupal site on a dedicated server that I run, where I installed the libX11 and used the most recent static version of wkhtmltopdf. That's on a CentOS 5 system and it runs nicely.
So, I have another hosting arrangement and I need to get the wkhtmltopdf to work, because it does the most amazing job producing bookmarked PDFs. The PDFs are beautiful.
The hosting is cPanel. I determined that it is on a server that has CentOS 5.5. It is not a problem to drop the static wkhtmltopdf in the print module's lib folder. However, I get the following message back in the Drupal admin status reports page (admin/reports/status).
It says,
"wkhtmltopdf library
The currently selected version of wkhtmltopdf () is not supported. Please update to a newer version."
I have obtained all of the needed .so files for CentOS 5, based on what jockie provided in his answer in the other StackOverflow thread.
Can someone knowledgeable confirm that his list was complete?
The idea of a shell script wrapper seems interesting and appears could be done for Drupal, if the naming of the shell script is called something like "wkhtmltopdf-wrapper.sh".
I have tried to use the shell script code that jockie provided, in a shell script. I did place all of the .so files in a sub-folder called "lib". I confess that I do not know what such things mean, in the script:
export HOME="$PWD"
Can someone interpret for me, what $PWD means?
export LD_LIBRARY_PATH="$PWD/lib/"
I understand that the script is going to get the .so files with that line, yes?
And can someone interpret the following line:
exec $# 2>/dev/null
What I am wondering is, where does the actual pdf get output? I did run the script. It did not throw any errors. However, I did not see a resulting PDF file.
Also, jockie's directions are not totally clear or defined enough. He says, "(some of them are symlinks)" under the list of .so files. Are such lines (in his list), the symlinks?:
lib/libX11.so.6 lib/libX11.so.6.2.0
Or am I mistaken? I was able to get all of them, so I don't know why they would be symlinks. The only thing is, that some of the versions are different. Do I need to delete the following files and make symlinks instead?:
lib/libX11.so.6
lib/libXau.so.6
lib/libxcb.so.1
lib/libXext.so.6
Should the shell script code be written differently, with Drupal in mind?
Thanks for reading and I hope someone can help!
...Finally, if anyone knows of a better solution, please share! Again, I appreciate the help!
...There does not seem to be a way, here on StackOverflow.com to notify jockie to check out this thread. I wish there was a way to write to them or notify them, so that they could clarify for them-self or contribute to this thread as well. If someone knows of a way, please let me know that too!

Resources