Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7770155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:20:22+00:00 2026-06-01T16:20:22+00:00

I have an R script with some inline C++, and I’d like to include

  • 0

I have an R script with some inline C++, and I’d like to include a header file in the same directory. I can get the following to work:

library(Rcpp)
library(inline)

code <- '
   // my C++ code here
   '

settings=getPlugin("Rcpp")
settings$env$PKG_CXXFLAGS='-I /hard/coded/path/to/header/'

myfunction <- cxxfunction(signature(x="numeric"),
                          plugin="Rcpp",  include='#include "myheader.hpp"',
                          settings=settings, body=code)

But it seems like there should be a convenient way to include a header file in the same directory. I just can’t see what it is. I’d really like a way to include c++ files which are located in the same directory.

(Also apologies: I’m not a c++ (or R) ninja, so I may be missing something very obvious.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:20:24+00:00Added an answer on June 1, 2026 at 4:20 pm

    Can you clarify what directory you refer to when you say “in the same directory”? Same as what?

    If it is the current directory, you still need -I. as that directory may not added as a default. But if that is indeed the directory you want, then its relative path (saying “current dir”) is more general than the absolute -I/hard/coded/path/to/header.

    Otherwise, what you have done is the correct way to modify the plugin to provide extra flags to the compiler.

    Edit: Made a test or two and it turns out that the inline package always use R’s tempdir to compile — so -I. makes no sense as we generally do not know where that is.

    That leaves you with two choices:

    1. Use an absolute path as you have done.

    2. Use R to read the content of the header file into a variable passed to the include= argument.

    Edit 2: Turns out that we do that in one of the examples shipped with Rcpp itself:

    settings <- getPlugin("Rcpp")
    settings$env$PKG_CXXFLAGS <- paste("-I", getwd(), sep="")
    

    and then uses settings=settings in the call to cxxfunction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a script that saves some files in the Documents directory of
I have a stand-alone svg file that displays without problems. It includes some inline
The script have some hard-coded relative paths. I would like them to be relative
Say I have something like this <script type=text/javascript src=somefile.js></script> <div>something</div> <script type=text/javascript> // Some
I need some help to get this to work. It works, but i have
We have a few places where we include inline <script> blocks which run code,
I have some script in my default page that redirects users to language specific
Suppose we have a BASH script running some commands in the background. At some
Trying to have my PHP script return some SQL table queries. Here's my script
I have a lingo script which runs some data processing for a Flash movie.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.