Use gsutil commands in R through system() -- which environmental variables do I need do assign? - r

Not sure how I should be going about this, but it is not working currently:
My first thought: in my home directory, I have the folder for GC SDK:
Sys.setenv(PATH="$HOME/google-cloud-sdk")
system(paste0("gsutil cp ",paste0(bucket,cancer.id,"/rnaseq_fpkm_*.csv "),paste0(cancer.id,"/rnaseq_fpkm_*.csv")),intern=F)
sh: 1: gsutil: not found
Warning message:
In system(paste0("gsutil cp ", paste0(bucket, cancer.id, "/rnaseq_fpkm_*.csv "), :
error in running command
Any assistance would be greatly appreciated.

If you want to add to your path rather than replace, the withr::with_path gives a good short term solution. You can also use expand.path to expand user paths to full paths. Try
withr::with_path( path.expand("~/google-cloud-sdk/bin/"), {
system(paste0("gsutil cp ",paste0(bucket,cancer.id,"/rnaseq_fpkm_*.csv "),paste0(cancer.id,"/rnaseq_fpkm_*.csv")),intern=F)
})
Or even just to check that it works, try
withr::with_path( path.expand("~/google-cloud-sdk/bin/"), {
print(Sys.getenv("PATH"))
print(Sys.which("gsutil"))
})

Related

Colab not recognising an existing directory

I have been trying to run an openpose model on colab but havent been able to do so because Colab doesn't recognise the directory. Screenshot of code
I have provided the code screenshot in this message, any help or direction will be highly appreciated!
Edit 1: A modification from the first answer
code:
!cd openpose && ./build/examples/openpose/openpose.bin -image_dir /drive/My\ Drive/research_project/Fall\ Detection/$category/testdata/video$video --render_pose 0 --disable_blending -keypoint_scale 3 --display 0 -write_json /drive/My\ Drive/research_project/Fall\ Detection/$category/jsondata/video$video
output:
Error:
Folder /drive/My Drive/research_project/Fall Detection/Coffee_room/testdata/video0/ does not exist.
I believe you need to remove the '..', as you are already in the '/content' folder from the os.chdir('/content') command
If that's not it, you also have a missing '/research project' after '/My Drive' in the line before the last
with the %cd operation you already moved yourself to [...]/Coffee_room/testdata, so when you try and os.chdir command, it throws an error. At least I think so, the screenshot doesn't let me copy the code to try and recreate the same situation, so it's a bit hard
Try to put your code in the right format inside the question like this
print('Hello, this is my code')

Failed to create wallet for ton with Fift?

Right now I'm trying to create wallet for TON.
I downloaded and built Fift interpreter an was trying to create new wallet with: ./crypto/fift new-walelt.fif
[ 1][t 0][1559491459.312618017][fift-main.cpp:147] Error interpreting standard preamble file `Fift.fif`: cannot locate file `Fift.fif`
Check that correct include path is set by -I or by FIFTPATH environment variable, or disable standard preamble by -n.
Although my path variable is set. Could anyone please help me with this?
First, locate {{lite-client-source-direcotry}}/crypto/fift
This is not the build directory, that's the directory where are the source files (lite-client that you downloaded). So verify you have that it contains Fift.fif file.
If you installed it in the user working directory, it should be:
~/lite-client/crypto/fift/
Now, you should either set FIFTPATH variable to point to this directory or run fift with -I option:
export FIFTPATH=~/lite-client/crypto/fift/
./crypto/fift new-walelt.fif
Or
./crypto/fift -I~/lite-client/crypto/fift/ new-walelt.fif
Have you tried ./crypto/fift -I<source-directory>/crypto/fift new-wallet.fif instead of setting environment variable? Are Fift.fif and Asm.fif library files inside FIFTPATH?
Make sure you have followed all the instruction written here:
https://test.ton.org/HOWTO.txt
It should work if you do all the above instruction correctly. If not, it might be a bug. Remember that TON is in a very early beta strage. You can submit the issue here:
https://github.com/copperbits/TON/issues
You also can use this:
cd ~/liteclient-build
crypto/fift -I/root/lite-client/crypto/fift/lib -s /root/lite-client/crypto/smartcont/new-wallet.fif -1 wallet_name
Try this (worked for me)
export FIFTPATH=~/lite-client/crypto/fift/lib
./crypto/fift new-wallet.fif

Error in system(command, intern = TRUE) : '“C:\Program' not found selectWeka function

I'm trying to run the code below from BioSeqClass package, however I get an error message:
Error in system(command, intern = TRUE) : '“C:\Program' not found
selectWeka(data, evaluator="CfsSubsetEval", search="BestFirst", n)
This is a problem with how BioSeqClass is calling java: it is leaving the file names unprotected/unquoted, and R's system and system2 commands are horrible by not forcing quoting. (If you ever think of using these commands directly yourself, I strongly recommend something like processx.)
One should create an issue or bug-report, but I don't know how to do that with Bioconductor, and their mirror on github (https://github.com/Bioconductor-mirror) is defunct, so I'm at a loss there. Hopefully somebody with more info can weigh in on this.
Workarounds
It is not obvious if the problem is due to where weka.jar is located or perhaps one of the other arguments. You can find out where the problem is by debugging the selectWeka function and inspecting the value of command before the system call. Look for the Program Files component of a path.
If the problem is with weka.jar, then this suggests that you are installing packages somewhere under C:\Program Files\, which is in my experience bad practice on two counts:
For many problems I cannot recall (but this one re-ignites the discussion), I never install R in the default location under C:\Program Files\...; instead, I install it under a new directory, C:\R\R-3.5.3 (version-based) and go from there. You may not have control over this if on a university/company system.
Since this is not in a base-R package, this suggests that either you are not using a personal library location (collection of packages), or have placed your personal library for some reason under C:\Program Files. If the former, I strongly suggest you never install new packages inside the base-R installation directory, instead using your own. See ?.libPaths and many other tutorials/discussions on the topic online. Using packrat or checkpoint might also mitigate this problem.
If the problem is with trainFile (if I'm reading the source correctly), then your "permanent" fix is to change where Windows puts temporary files, as this trainFile is a temporary file created specifically for this function-run. If this is your problem, I'll leave it up to you to fix.
Regardless, you may not have time or need to make a more permanent solution, you just want to run this once or twice and then move on. For that fix:
Again, debug(selectWeka), and once command is defined (the next command to be executed is tmp <- system(command,intern = TRUE)), run this code to fix the value of command:
if(search=="Ranker"){
command = paste("java -cp ", shQuote(file.path(.path.package("BioSeqClass"), "scripts", "weka.jar")),
" weka.attributeSelection.", evaluator, " -i ", shQuote(trainFile),
" -s \"weka.attributeSelection.", search, " -N ", n, "\"", sep="" )
}else{
command = paste("java -cp ", shQuote(file.path(.path.package("BioSeqClass"), "scripts", "weka.jar")),
" weka.attributeSelection.", evaluator, " -i ", shQuote(trainFile),
" -s weka.attributeSelection.", search, sep="" )
}
(For the record, all I changed was adding shQuote twice to each paste.) Confirm that command now has quotes around things, something like
Browse[2]> command
[1] "java -cp \"C:\\Program Files\\...\\weka.jar" weka.attributeSel... -i \"c:\\path\\to\\some\\tempfile\" ...
Then you can continue-out of the debugger and let it run its course.
(I hope you don't have hundreds of calls to selectWeka.)
Caveat: I am not a use of BioSeqClass, so I'm saying all of this from speculation and inference. I might have mis-located the source of the error. And since I don't know what I'm doing with it, I have not tested the modified command assignment within selectWeka. I believe shQuote(...) is the right way to go, but you might need to use sQuote or dQuote instead, I'm not sure how your system is setup.

Debugging bitbake pkg_postinst_${PN}: Append to config-file installed by other recipe

I'm writing am openembedded/bitbake recipe for openembedded-classic. My recipe RDEPENDS on keyutils, and everything seems to work, except one thing:
I want to append a single line to the /etc/request-key.conf file installed by the keyutils package. So I added the following to my recipe:
pkg_postinst_${PN} () {
echo 'create ... more stuff ..' >> ${sysconfdir}/request-key.conf
}
However, the intended added line is missing in my resulting image.
My recipe inherits update-rc.d if that makes any difference.
My main question is: How do i debug this? Currently I am constructing an entire rootfs image, and then poke-around in that to see, if the changes show up. Surely there is a better way?
UPDATE:
Changed recipe to:
pkg_postinst_${PN} () {
echo 'create ... more stuff ...' >> ${D}${sysconfdir}/request-key.conf
}
But still no luck.
As far as I know, postinst runs at rootfs creation, and only at first boot if rootfs fails.
So there is a easy way to execute something only first boot. Just check for $D, like this:
pkg_postinst_stuff() {
#!/bin/sh -e
if [ x"$D" = "x" ]; then
# do something at first boot here
else
exit 1
fi
}
postinst scripts are ran at roots time, so ${sysconfdir} is /etc on your host. Use $D${sysconfdir} to write to the file inside the rootfs being generated.
OE-Classic is pretty ancient so you really should update to oe-core.
That said, Do postinst's run at first boot? I'm not sure. Also look in the recipes work directory in the temp directory and read the log and run files to see if there are any clues there.
One more thing. If foo RDEPENDS on bar that just means "when foo is installed, bar is also installed". I'm not sure it makes assertions about what is installed during the install phase, when your postinst is running.
If using $D doesn't fix the problem try editing your postinst to copy the existing file you're trying to edit somewhere else, so you can verify that it exists in the first place. Its possible that you're appending to a file that doesn't exist yet, and the the package that installs the file replaces it.

no rules to make target 'micaz'

I am a new in Tinyos.
I am following the tinyos Tutorial lesson 3: Mote-mote radio communication.
When I use 'make' to compile the program BlinkToRadio in lesson 3, I got a error message:
make: *** No rule to make target 'micaz'. Stop.
But when I compile the program Blink, it works. So I dont think its the problem in enviorement variables.
Can anyone help me what it the problem.
Thank you!
this is a problem in the file Makefile, in the next code:
COMPONENT=BlinkToRadioAppC
include $(MAKERULES)
sometimes there is a space after $, or some other error.
Are you using sudo when you're trying to build the app? sudo will likely reset all your environment variable while you're using sudo. You can set env_keep in the /etc/sudoers file to keep your $MAKERULES
Defaults env_keep += "MAKERULES"
or you could look at this
Of course, it could be something entirely different....
Have you defined a Makefile? The Makefile for lesson 3 should be:
COMPONENT=BlinkToRadioAppC
include $(MAKERULES)
Have you defined MAKERULES?
You can check the definition of MAKERULES this way:
echo $MAKERULES
If not defined, you can define MAKERULES this way:
export MAKERULES=/opt/tinyos-2.1.0/support/make/MAKERULES
I got the same errors. There are 2 ways to solve it..... Do not run the code as root. This works for sure.
2nd I am not so sure but if at all you want to run as root, try sudo bash and not other commands.
Hope this helps

Resources