1

I think there is a problem in my shiny script, with executing a shell comand and I was wondering if there maybe is a way to do this command within shiny.

Outside of shiny my code functions.

#Function to calculate maxentscore
calculate_maxent <- function(seq_vector,maxent_type){

  #Save working directory from before
  Current_wkdir <- getwd()

  #First, change working directory, to perl script location
  setwd("S:/Arbeitsgruppen VIRO/AG_Sch/Johannes Ptok_JoPt/Rpackages/rnaSEQ/data/maxent")

  #Create new text file with the sequences saved
  cat(seq_vector,file="Input_sequences",sep="\n",append=TRUE)

  #Execute the respective Perl script with the respective Sequence file
  if(maxent_type == 3) cmd <- paste("score3.pl", "Input_sequences")
  if(maxent_type == 5) cmd <- paste("score5.pl", "Input_sequences")

  #Save the calculated Maxent score file
  x <- shell(cmd,intern=TRUE)

  #Reset the working directory
  setwd(Current_wkdir)

  #Substracting the Scores from the Maxent Score Table
  x <- substr(x,(regexpr("\t",x)[[1]]+1),nchar(x))

  #Returning the maxent table
  return(x)

}

So basically I just try to execute following code:

shell("score5.pl Input_sequences")

This does seem to not be possible that way within shiny

1
  • Hi Ptok, were you able to get this working ? I'm trying something similar, and was wondering if it is possible to do Commented Aug 1, 2023 at 19:34

1 Answer 1

1

I do not know the shell command, but executing shell commands is possible via system(). It even uses the current working directory set by R.

So you might try:

x <- system(cmd, intern=True)
1
  • Thanks for the answer. However it turned out, that the problem was not the shell function, but the way I created the text file beforhand. EDIT: If the file with the specific names is already there, the cat function just adds the lines to that file. I solved the problem by deleting the file "Input_seq" before using the cat function. Commented Jan 17, 2018 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.