I want to write an R package and release on CRAN. But I have concerns about legal issues: licensing and authorship/ownership.

Code of some functions in the package will be derived from or based on posts in websites like these:

A. this answer and this code for function 1;
B. this comment for several other functions.

Can I legally use these codes as I can't find any license they are under? I.e. Are there any legal restrictions at all to include code from forum websites in a package? Who is the owner of copyright licenses in this case, if any?

Are there any legal differences in cases where:
(a) the initial piece of code was written by me and then other forum users corrected/updated it?
(b) I just asked a question and got an answer (a piece of code)?

A related question about how to attribute authors when their real names are unclear is here.

  • These are quite possibly 3 different questions, and different people may be able to answer each of them. If you agree, would you like to split them up? eg. I could answer #1 and probably #3 for you, but I don't know R or CRAN well enough to answer #2.
    – Tim Malone
    Commented Jun 7, 2016 at 20:11
  • @Tim Malone, I split the questions into several pieces. Question about authorship is here.
    – GegznaV
    Commented Jun 8, 2016 at 16:37
  • Oh dear. I thought they fit better together unified. But oh well. Differing opinions are something alright. Anyways... Vilmantas, it would be very helpful if you could tell us where in the world you are (over here, and on your other question). Although copyright is generally pretty uniform, it would be helpful, as laws vary by jurisdiction. Thanks! :)
    – Zizouz212
    Commented Jun 8, 2016 at 20:27
  • Of course laws differ from country to country. But I thought that there are some common international rules, as releasing R package is a global event. I am from European Union.
    – GegznaV
    Commented Jun 8, 2016 at 22:23

1 Answer 1


You're essentially asking here:
Can I legally use code I found on a forum?

The short answer is 'it depends'. And by the way, IANAL/TINLA.

It depends on:

  • whether the code is eligible for copyright,
  • what license the content of the particular forum is under, and
  • what additional license (if any) the individual contributor has put it under.

The code you've linked to comes from StackOverflow, a GitHub Gist, and a post in a GitHub issue.

The first thing you need to consider is whether the code is copyrightable at all. Quoting from a comment made by leezer3 on another post: "In order to be copyrightable (under UK/European law at least) the work must not be a simple mathematical algorithm, and must have unique properties." In other words, there needs to be something creative about it.

If it's simple enough, you can use it - no problem (I'd usually still include a comment linking to the post it came from though). If it's more complex, can you take the idea of the solution and completely rewrite it "in your own words"? If so, you now own the copyright on it (when doing this I still tend to comment with the original post as a sort of 'hat tip', but that's not required).

If it's not simple and you can't/don't want to rewrite it, then you need to consider how it's licensed on the website or forum you found it on. In the case of all StackExchange sites, scroll to the bottom where you'll see a link to CC BY-SA 3.0. You are free to use and change any content (code or text) that you find on SE sites, as long as you give credit and as long as you continue to share in the same manner any changes you make.

As far as giving credit, this blog post (also linked from the footer of every page) explains how StackExchange would like you to give that attribution. This post is written for websites who use SE content wholesale, so I tend to take a slightly different approach in code: I just ensure that I link in a comment to the original post so it's clear where it came from.

As far as sharing any adaptions in a like manner, this is where it can get a bit murky and where it's probably better to just rewrite what you find anyway. Depending on the license of your final product, you might be able to relicense your adaptions - see this answer for a path to license CC BY-SA content under the GPL.

In the case of GitHub Gists and Issues, anything posted on GitHub is owned by the original contributor and is not covered by a blanket license. So, it is automatically theirs unless they've given you a specific license to use it.

While I would assume someone posting code in a Gist or Issue would be happy for you to use it, to be safe you really need to ask them for permission. They might license it to you under the MIT or they might just say you can do whatever you like with it. Either way, crediting them with a comment linking to the Gist/Issue is the appropriate thing to do.

Finally, one additional consideration is whether the contributor has put their code under any additional license. On StackExchange, some users say in their profile that their code is also available under the Apache or MIT licenses, or released into the public domain. On GitHub, look for a comment or message to a similar effect on the user's profile.

If in doubt, you can try to contact that user directly and many will be happy to give you additional permissions.

In answer to your additional questions:

Are there any legal differences where ... the initial piece of code was written by me and then other forum users corrected/updated it?

Possibly. Going back to whether the code is eligible for copyright, if the updates were wholesale contributions that are copyrightable on their own, then technically the user who made those changes owns the copyright, and you would need to apply the guidelines I went through above if you want to use those contributions.

Are there any legal differences where ... I just asked a question and got an answer (a piece of code)?

No. Whether or not you asked the question and got a piece of code in response makes no difference to any copyright and license that may or may not be on that code.

One final consideration: if you use code you find on a public forum, you are still responsible for ensuring you are using it correctly. You'll want to be very sure that the person who posted code you use is really the copyright owner of the code, and that they didn't just copy it from somewhere else. Because of this, to be safe, you might want to just take most forum posts as 'suggestions' and use the ideas to write the code yourself.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.