0

I am trying to mimic the results of a fasttext command line operation in R using the system function. When I run the prompt in the command line I get the desired results as below:

F:\>fasttext print-sentence-vectors model.bin < sentences.txt
   0.072631 0.036104 0.0046829 0.057456 0.03449

When I try to mimic this in R I get the following:

> system("fasttext print-sentence-vectors model.bin < sentences.txt")
  usage: fasttext print-sentence-vectors <model>

  <model>      model filename

  [1] 1

I believe the issue is the requirement of "<" in the command line since when I remove it from the command line prompt I get

F:\>fasttext print-sentence-vectors model.bin sentences.txt
usage: fasttext print-sentence-vectors <model>

<model>      model filename

Same as what I get in R. So my question is, how do I go about resolving this in R ? I tried various versions with the paste function as well as wrapping the < in quotes but nothing seemed to work.

Tried shell() as per a comment below and got this error message

> shell("fasttext print-sentence-vectors model.bin < sentences.txt")
'\\mypathname\fasttextstuff'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
The system cannot find the file specified.
Warning message:
In shell("fasttext print-sentence-vectors model.bin < sentences.txt") :
  'fasttext print-sentence-vectors model.bin < sentences.txt' execution failed with error code 1

Turns out shell() worked as per the comment below with a directory change.

6
  • 2
    The redirection symbol < is handled by your command shell, not by fasttext. It looks as though you are on Windows, and on that OS R doesn't run a shell when running system(). Use shell() instead. Commented Aug 1, 2023 at 12:23
  • Tried that, didn't work, will edit question with the error message Commented Aug 1, 2023 at 12:25
  • 3
    Looks like your current directory is something that CMD.EXE doesn't support. It's been a long time since I used Windows, so I don't know the current workarounds. In the old days you'd set up a drive letter for the UNC path, and use something like cd D: to make it current. Commented Aug 1, 2023 at 12:41
  • Ahh yea changed the directory and it works now. Thanks Commented Aug 1, 2023 at 13:01
  • 1
    I mean, the comment answered the question, wouldn't it be more appropriate for the commenter to write the answer? Commented Aug 1, 2023 at 13:41

1 Answer 1

2

The redirection symbol < is handled by your command shell, not by fasttext. It looks as though you are on Windows, and on that OS R doesn't run a shell when running system(). Use shell() instead.

After that failed, this fixes it: make sure that your current directory uses a drive letter (e.g. D:), not a UNC path, which CMD.EXE doesn't like.

Sign up to request clarification or add additional context in comments.

Comments

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.