Are there general guidelines for including code in a research paper?
In general, I would never include code in the "main" paper outside of computer science or applied mathematics. There are very few cases where listing code explicitly would actually improve the quality and readability of the paper. If it is necessary to include the code, I would do so as part of the "Supporting Information" which many journals allow you to include alongside the main publication. I would then describe the features of the code as words in the main text.

Even in CS and math papers, I would still only put pseudocode in the main article, and would save any listings of actual code for the Supporting Information.